我们部门正在进行一些交通报告。
因此,我们建立了一个名为traffic_report的表格,其结构如下:
╔════════════════╦═══════════╦═════════════════════╦═════════════╦═════════════╗
║ hostname ║ interface ║ date_gmt ║ intraf_mpbs ║ outraf_mbps ║
╠════════════════╬═══════════╬═════════════════════╬═════════════╬═════════════╣
║ my-machine.com ║ NIC-5 ║ 2013-09-18 09:55:00 ║ 32 ║ 22 ║
║ my-machine.com ║ NIC-5 ║ 2013-09-17 08:25:00 ║ 55 ║ 72 ║
║ my-machine.com ║ NIC-5 ║ 2013-09-16 05:12:00 ║ 65 ║ 2 ║
║ my-machine.com ║ NIC-5 ║ 2013-09-15 04:46:00 ║ 43 ║ 5 ║
║ my-machine.com ║ NIC-5 ║ 2013-09-14 12:02:00 ║ 22 ║ 21 ║
║ my-machine.com ║ NIC-5 ║ 2013-09-13 22:13:00 ║ 66 ║ 64 ║
╚════════════════╩═══════════╩═════════════════════╩═════════════╩═════════════╝
我希望获取发生日期内流入和流出流量的最大值。我这样做的方法如下:
SELECT hostname, interface, date_gmt, max(intraf_mbps) as max_in, max(outtraf_mbps) as max_out
FROM traffic_report
GROUP by hostname, interface
这种方法会生成一个类似这样的表格:
╔════════════════╦════════════╦═════════════════════╦════════╦═════════╗
║ hostname ║ interface ║ date_gmt ║ max_in ║ max_out ║
╠════════════════╬════════════╬═════════════════════╬════════╬═════════╣
║ my-machine.com ║ NIC-5 ║ 2013-09-18 09:55:00 ║ 66 ║ 72 ║
╚════════════════╩════════════╩═════════════════════╩════════╩═════════╝
问题是,显示的date_gmt只是表中输入的第一条记录的日期。
我该如何指示SQL显示最大intraf_mbps发生的date_gmt?