sql三條,分別求每天的行程量,每週的,每月的
這一年內每個月的資料
select
monthname(start_time) month,
sum( time_to_sec( timediff(end_time, start_time) )) secondsoftime,
sum( time_to_sec( timediff(end_time, start_time) ) / 60) minuteoftime,
sum(mileage) mileage
from
electrombile_trip_record
where
year(start_time) = year(now())
group by
monthname(start_time)
這一季度每週的資料
select
weekofyear(start_time) week,
sum( time_to_sec( timediff(end_time, start_time) )) secondsoftime,
sum( time_to_sec( timediff(end_time, start_time) ) / 60) minuteoftime,
sum(mileage) mileage
from
electrombile_trip_record
where
quarter(start_time) = quarter(now())
group by
weekofyear(start_time)
這乙個月每天的資料
select
date(start_time) daydate,
dayofmonth(start_time) day,
sum( time_to_sec( timediff(end_time, start_time) )) secondsoftime,
sum( time_to_sec( timediff(end_time, start_time) ) / 60) minuteoftime,
sum(mileage) mileage
from
electrombile_trip_record
where
month(start_time) = month(now())
group by date(start_time),
dayofmonth(start_time)
學習和參考:
Mysql 時間處理函式使用
一 基本介紹 1.to days date 給出乙個日期 date,返回乙個天數 從 0 年開始的天數 mysql select to days 20110311 to days 20110311 734572 1 row in set 0.00 sec mysql select to days 1...
mysql時間函式
這些函式都是mysql自帶的,可以直接使用在php寫的mysql查詢語句中哦 1 curdate 或current date 和curtime 或current time 這兩個函式是比較常用到的,顧名思義,第乙個返回當前日期,第二個返回當前時間 可以在mysql客戶端或者php語句裡寫 selec...
mysql時間函式
unix timestamp unix timestamp date 若無引數呼叫,則返回乙個unix timestamp 1970 01 01 00 00 00 gmt 之後的秒數 作為無符號整數。若用date 來呼叫unix timestamp 它會將引數值以 1970 01 01 00 00 ...