• Resolved rkasinski

    (@rkasinski)


    Hello,

    I have a database with id, datetime and status.

    I need to do the chart with presenting counted status, divided by hours in defined day. Problem is that in chart I cannot do the sorting by hours like below.

    ORDER BY godzine is not working, same results

    My SQl is :

    SELECT HOUR (datetime) AS godzina, COUNT(*) As total
    FROM winding_h_6ms
    WHERE STATUS LIKE “OFFLINE” AND datetime LIKE CONCAT(LEFT({sel_date},10),”%”)
    GROUP BY godzina;

    SELECT HOUR (datetime) AS godzina, COUNT(*) As total
    FROM winding_h_6ms
    WHERE STATUS LIKE “ONLINE” AND datetime LIKE CONCAT(LEFT({sel_date},10),”%”)
    GROUP BY godzina;

    SELECT HOUR (datetime) AS godzina, COUNT(*) As total
    FROM winding_h_6m
    WHERE STATUS LIKE “WORKING” AND datetime LIKE CONCAT(LEFT({sel_date},10),”%”)
    GROUP BY godzina ;

    SELECT HOUR (datetime) AS godzina, COUNT(*) As total
    FROM winding_h_6m
    WHERE STATUS LIKE “ERROR” AND datetime LIKE CONCAT(LEFT({sel_date},10),”%”)
    GROUP BY godzina

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Guaven Labs

    (@elvinhaci)

    Hi. Have you tried to run the query in phpMyAdmin first? Because we run SQL directly without changing anything in orderby clause.

    Thread Starter rkasinski

    (@rkasinski)

    When I run separately the query in MyAdmin, then is working fine. But when I generate charts the resuls is like I attached.

    Plugin Author Guaven Labs

    (@elvinhaci)

    [“9″,”16″,”17″,”18″,”19″,”20″,”21”] – but they are ordered correctly. What is your expected order in this array?

    Thread Starter rkasinski

    (@rkasinski)

    Hi, I think I have found solution, I change SQL query. Previus generates 9,19,20,16,17,18 – looks that You don’t see attahced picture.

    No i load Query like below, and I tested.

    SELECT
    HOUR(datetime) AS godzina,
    SUM(CASE WHEN status LIKE ‘%ONLINE%’ THEN 1 ELSE 0 END) AS total
    FROM winding_h_6m
    WHERE
    HOUR(datetime) BETWEEN 6 AND 23 AND datetime LIKE CONCAT(LEFT(‘2025-0-06,10’),”%”)

    GROUP BY
    HOUR(datetime)
    ORDER BY
    godzina;

    Thread Starter rkasinski

    (@rkasinski)

    Issue was in SQL string.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.