sql月度彙總 sql月份彙總查詢語句

2021-10-21 08:13:37 字數 963 閱讀 7539

sql月份彙總查詢語句

select '鉛筆' as [月份],

sum(case month(日期) when 1 then 鉛筆 else 0 end) as [1月],

sum(case month(日期) when 2 then 鉛筆 else 0 end) as [2月],

sum(case month(日期) when 3 then 鉛筆 else 0 end) as [3月],

sum(case month(日期) when 4 then 鉛筆 else 0 end) as [4月],

sum(case month(日期) when 5 then 鉛筆 else 0 end) as [5月],

sum(鉛筆) as 總價

from table

union all

select '鋼筆' as [月份],

sum(case month(日期) when 1 then 鋼筆 else 0 end) as [1月],

sum(case month(日期) when 2 then 鋼筆 else 0 end) as [2月],

sum(case month(日期) when 3 then 鋼筆 else 0 end) as [3月],

sum(case month(日期) when 4 then 鋼筆 else 0 end) as [4月],

sum(case month(日期) when 5 then 鋼筆 else 0 end) as [5月],

sum(鋼筆) as 總價

from table

結果鉛筆 1月 2月 3月 4月 5月 總價

鉛筆 200 500 600 700 500 2500

鋼筆 200 300 250 400 300 1450

毛筆 300 400 500 300 600 2100

總價 700 1200 1350 1400 1400 6050

sql月度彙總 按月度分類彙總

按月份分類彙總 id 訂單號 日期 1 cno001 2013 6 5 2 cno001 2013 6 10 3 cno002 2013 6 24 4 cno001 2013 7 5 5 cno001 2013 7 10 6 cno002 2013 7 15 得到結果 訂單號 月份 cno001 2...

SQL語句彙總

檢視oracle伺服器端字符集 select from nls database parameters 檢視oracle客戶端字符集 select from nls instance parameters 全庫匯出資料 exp 使用者名稱 密碼 遠端的ip 埠 例項 file 存放的位置 檔名稱.d...

SQL語句彙總

sql語句彙總 一 資料庫 1.建立資料庫 create database name 2.檢視資料庫 show databases 3.選擇資料庫 use name 4.刪除資料庫庫 drop database name 二 表 1.建立表 create table name 屬性名 資料型別 屬性...