你這頂多只能說是 "SQL"指令
似乎沒看到有 『MySQL 自己才有的東西』?
SQL 還有很多有趣的東西
Ex:
select U.device_id as ID, CONCAT(year(U.time),"-",right(concat("0",month(U.time)),2),"-",right(concat("0",day(U.time)),2), " ", hour(U.time),":00:00") as T , max(U.humidity) as MA, min(U.humidity) as MI, avg(U.humidity) as AV from sensing_data_humidity as U where hour(U.time)>9 and hour(U.time)<19 and month(U.time)=9 group by T, ID order by T, ID limit 24;
這樣 會幫你把 不同 device 每小時的 humidity值 自動做好 平均值 跟 最大/最小值 算好!
(只看前 24筆資料!)
... 另一種更簡潔的寫法:
select U.device_id as ID, DATE_FORMAT(U.time,'%Y-%m-%d %H:00:00') as T , max(U.humidity) as MA, min(U.humidity) as MI, avg(U.humidity) as AV from sensing_data_humidity as U where hour(U.time)>9 and hour(U.time)<19 and month(time)=9 group by T, ID order by T, ID limit 24;
其他 Function, ref:
http://dev.mysql.com/doc/refman/5.0/en/functions.html
另,
3. VARCHAR (不超過255字元不定長度字串)
4. TEXT (不定長度字串最多65535字元)
這兩個 除了支援的長度外 有啥不同?
|