TFC TFC - 5 months ago 12
MySQL Question

How can I get max value of two column in manpulated table in MySQL

I have a table and I manipulated it to cretae some graph. Here is original table

select * from traffic_user_daily;
+-------------------+------------+-------+---------+----------+
| username | cdate | chour | bytesin | bytesout |
+-------------------+------------+-------+---------+----------+
| 00:09:df:89:81:f2 | 2016-05-27 | 16 | 16469 | 10321 |
| 00:09:df:89:81:f2 | 2016-05-27 | 18 | 599161 | 121796 |
| 00:09:df:89:81:f2 | 2016-05-27 | 19 | 21058 | 11141 |
| 00:09:df:89:81:f2 | 2016-05-28 | 08 | 20608 | 72061 |
| 00:09:df:89:81:f2 | 2016-05-28 | 09 | 359375 | 176809 |


And I run sıme query like this:

SELECT CONCAT(cdate,' ',chour,':00:00') AS ctime ,sum(bytesin*0.000002222) as totalKbpsin, sum(bytesout*0.000002222) as totalKbpsout FROM traffic_user_daily group by cdate,chour HAVING ctime >= now() - INTERVAL 1 DAY

+---------------------+----------------+----------------+
| ctime | totalKbpsin | totalKbpsout |
+---------------------+----------------+----------------+
| 2016-05-31 10:00:00 | 1230.390102018 | 772.301406580 |
| 2016-05-31 11:00:00 | 2554.907603688 | 1185.870290000 |
| 2016-05-31 12:00:00 | 2260.437353658 | 295.407289650 |
| 2016-05-31 13:00:00 | 3031.315984752 | 316.283035200 |
| 2016-05-31 14:00:00 | 3872.374530486 | 720.599486178 |


But dont know how to get MAX values of totalKbpsin and totalKbpsout columns.
Cand you help me?
Regards,

TFC TFC
Answer

$query_IO ="

SELECT  MAX(totalKbpsin),MAX(totalKbpsout)
    FROM  
      ( SELECT  CONCAT(cdate,' ',chour,':00:00') AS ctime ,sum(bytesin*0.000002222) as totalKbpsin,
                sum(bytesout*0.000002222) as totalKbpsout
            FROM  traffic_user_daily
            group by  cdate,chour
            HAVING  ctime >= now() - INTERVAL 1 DAY
      ) a 

";

solved my problem. Thnaks for your assistance...

Comments