我有以下输出:
root@localhost [hatsize]> SELECT COUNT(*) AS VMS,sysname,DAYNAME(Start),DATE(Start) from complete_ev WHERE type = 's' GROUP BY DAYOFYEAR(Start),sysname ORDER BY VMS DESC;
+-----+---------+----------------+-------------+
| VMS | sysname | DAYNAME(Start) | DATE(Start) |
+-----+---------+----------------+-------------+
| 85 | sv-esx5 | Monday | 2013-09-16 |
| 63 | sv-esx6 | Wednesday | 2013-09-18 |
| 60 | sv-esx5 | Monday | 2013-09-09 |
| 55 | sv-esx6 | Monday | 2013-09-16 |
| 52 | sv-esx6 | Monday | 2013-09-09 |
| 51 | sv-esx5 | Wednesday | 2013-09-18 |
| 50 | sv-esx7 | Wednesday | 2013-09-11 |
| 44 | sv-esx4 | Monday | 2013-09-09 |
| 43 | sv-esx4 | Tuesday | 2013-09-10 |
| 34 | sv-esx4 | Tuesday | 2013-09-17 |
| 34 | sv-esx7 | Monday | 2013-09-09 |
| 34 | sv-esx4 | Monday | 2013-09-16 |
| 34 | sv-esx7 | Tuesday | 2013-09-17 |
| 34 | sv-esx6 | Wednesday | 2013-09-11 |
| 34 | sv-esx7 | Monday | 2013-09-16 |
| 30 | sv-esx5 | Wednesday | 2013-09-11 |
| 30 | sv-esx5 | Thursday | 2013-09-12 |
| 18 | sv-esx7 | Wednesday | 2013-09-18 |
| 17 | sv-esx6 | Tuesday | 2013-09-17 |
| 17 | sv-esx6 | Tuesday | 2013-09-10 |
| 17 | sv-esx7 | Thursday | 2013-09-12 |
| 13 | Pod130 | Wednesday | 2013-09-11 |
| 10 | sv-esx4 | Friday | 2013-03-22 |
| 9 | sv-esx4 | Sunday | 2013-09-08 |
| 9 | sv-esx2 | Wednesday | 2013-09-11 |
| 9 | sv-esx2 | Tuesday | 2013-09-10 |
| 9 | Pod130 | Thursday | 2013-09-12 |
| 9 | sv-esx4 | Wednesday | 2013-09-11 |
| 9 | sv-esx5 | Friday | 2013-09-13 |
| 9 | sv-esx4 | Friday | 2013-09-13 |
| 9 | sv-esx2 | Monday | 2013-09-09 |
| 9 | sv-esx5 | Tuesday | 2013-09-10 |
| 2 | sv-esx2 | Friday | 2012-07-27 |
+-----+---------+----------------+-------------+
33 rows in set (0.00 sec)
即使在没有用的日子里,我也喜欢获得每个系统名的每日平均值,另一个转折是我想排除星期六。我尝试了一些东西,但我看不出想出正确的公式。以下是对该表的说明:
root@localhost [hatsize]> desc complete_ev;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| EventID | int(16) | YES | | NULL | |
| Start | datetime | YES | | NULL | |
| End | datetime | YES | | NULL | |
| Cname | varchar(100) | YES | | NULL | |
| Template | varchar(100) | YES | | NULL | |
| pod | varchar(100) | YES | | NULL | |
| sysname | varchar(100) | YES | | NULL | |
| type | char(10) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
8 rows in set (0.00 sec)
这实际上是一个视图:
show create table complete_ev\G
*************************** 1. row ***************************
View: complete_ev
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `complete_ev` AS select `e`.`EventID` AS `EventID`,`e`.`Start` AS `Start`,`e`.`End` AS `End`,`e`.`Name` AS `Cname`,`e`.`template` AS `Template`,`d`.`pod` AS `pod`,`d`.`name` AS `sysname`,`d`.`type` AS `type` from (`FutEv` `e` join `equip` `d` on((`e`.`EventID` = `d`.`EventID`))) where (`e`.`Status` = _latin1'i')
谢谢!