如圖,該數(shù)據(jù)透視表是以每天進行日期分組,現(xiàn)在需要把它們修改為以季度分組。
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:申請域名、虛擬空間、營銷軟件、網(wǎng)站建設、石河子網(wǎng)站維護、網(wǎng)站推廣。
選中某一個日期。
點擊“選項”。
點擊“將所選內(nèi)容分組”。
將“終止于”前面的鉤取消。
輸入這一年的最后一天。
選擇“季度”。
點擊“確定”。
如此,設置成功。
SELECT DATE_FORMAT(time,'%Y-%m-%d') as day, sum(case when amount0 then amount when amount=0 then 0 end) as amount1
from table where time='2014-11-01' group by day;
我沒有測試。time表示日期,amount表示數(shù)量。查詢11月后每天成交數(shù)量
您好,一、年度查詢
查詢 本年度的數(shù)據(jù)
SELECT *
FROM blog_article
WHERE year( FROM_UNIXTIME( BlogCreateTime ) ) = year( curdate( ))
二、查詢季度數(shù)據(jù)
查詢數(shù)據(jù)附帶季度數(shù)
SELECT ArticleId, quarter( FROM_UNIXTIME( `BlogCreateTime` ) )
FROM `blog_article`
其他的同前面部分:查詢 本季度的數(shù)據(jù)
SELECT *
FROM blog_article
WHERE quarter( FROM_UNIXTIME( BlogCreateTime ) ) = quarter( curdate( ))
三、查詢月度數(shù)據(jù)
本月統(tǒng)計(MySQL)
select * from booking where month(booking_time) =
month(curdate()) and year(booking_time) = year(curdate())
本周統(tǒng)計(MySQL)
select * from spf_booking where month(booking_time) =
month(curdate()) and week(booking_time) = week(curdate())
四、時間段
N天內(nèi)記錄
WHERE TO_DAYS(NOW()) - TO_DAYS(時間字段) = N
當天的記錄
where date(時間字段)=date(now())
或
where to_days(時間字段) = to_days(now());
查詢一周:
select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) = date(column_time);
查詢一個月:
select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) = date(column_time);
查詢'06-03'到'07-08'這個時間段內(nèi)所有過生日的會員:
Select * From user Where
DATE_FORMAT(birthday,'%m-%d') = '06-03' and DATE_FORMAT(birthday,'%m-%d')
= '07-08';
統(tǒng)計一季度數(shù)據(jù),表時間字段為:savetime
group by concat(date_format(savetime, '%Y '),FLOOR((date_format(savetime, '%m ')+2)/3))
或
select YEAR(savetime)*10+((MONTH(savetime)-1) DIV 3) +1,count(*)
from yourTable
group by YEAR(savetime)*10+((MONTH(savetime)-1) DIV 3) +1;
五、分組查詢
1、年度分組
2、月度分組
3、先按年度分組,再按月度分組
4、按年月分組
SELECT count(ArticleId), date_format(FROM_UNIXTIME( `BlogCreateTime`),'%y%m') sdate FROM `blog_article` group by sdate
結(jié)果:
count( ArticleId ) sdate
17 0901
11 0902
5 0903
6 0904
2 0905
1 0907
12 0908
6 0909
11 0910
3 0911
假設你的表為 ta 日期字段是 dt
那么,以 2015-01-01為起始日,每5天累總計數(shù)為:
select datediff(dt, '2015-01-01') div 5 as d5 , count(*)
from ta
group by (datediff(dt, '2015-01-01') div 5)
3.按季度分組
select to_char(exportDate,'yyyy-Q'),sum(amount) from table1 group by to_char(exportDate,'yyyy-Q')
order by to_char(exportDate,'yyyy-Q');
試試這個吧
和按月份組的原理是一樣的吧!
按月分組
按季度分組和按月分組的區(qū)別應該就是時間段的區(qū)別吧!
select?case?when??month(date)??=1?or?month(date)?=2?
or?month(date)=3???then?'一季度'?
when??month(date)??=4?or?month(date)?=5?
or?month(date)=6???then?'2季度'?
when??month(date)??=7?or?month(date)?=8?
or?month(date)=9???then?'3季度'?
when??month(date)??=10?or?month(date)?=11?
or?month(date)=12???then?'4季度'?
else?''?end?,sum(數(shù)量)
from?table?
group?by??
case?when??month(date)??=1?or?month(date)?=2?
or?month(date)=3???then?'一季度'?
when??month(date)??=4?or?month(date)?=5?
or?month(date)=6???then?'2季度'?
when??month(date)??=7?or?month(date)?=8?
or?month(date)=9???then?'3季度'?
when??month(date)??=10?or?month(date)?=11?
or?month(date)=12???then?'4季度'?
else?''?end