sql分類匯總
❶ sql 分類匯總
selectmonth,
sum(casewhencreatedby='CM.KAEast'then1else0end)East,
sum(casewhencreatedby='CM.KASouth'then1else0end)South,
sum(casewhencreatedby='CM.KAWest'then1else0end)West,
sum(casewhencreatedby='CM.KANorth'then1else0end)North
from
(,createdbyfrom表名
unionall
,createdbyfrom表名
unionall
,createdbyfrom表名
unionall
,createdbyfrom表名)ast
groupbymonth
❷ SQL條件分類匯總
只會點SQL 語句,寫下來看看!代碼如下:
1:
select 用戶號,sum(收入) as 家庭收入,社區名 from shequbiao
group by 用戶號,社區名
2:
先創建一個帶參數的存儲過程:
create procere 存儲過程名
@id char(4)
as
update shequbiao set 社區名=(select 社區名 from shequbiao where 用戶類型='戶主'and 用戶號=@id )
where 用戶號=@id
然後執行:
exec 存儲過程名 參數
3:
select 用戶號 , sum(收入) as 家庭總收入,count(*)as 家庭總人數 ,用戶名=(select 用戶名 from shequbiao aa where 用戶類型='戶主'and aa.用戶號=bb.用戶號)
from shequbiao bb
group by 用戶號
order by sum(收入) desc
❸ SQL分類匯總
同樣,不同sql方言,字元串連接可能要適當改變
需要注意的是一定要用UNION ALL,而不是UNION
SELECT 'Sub'|| year|| '-' ||item,
SUM(num)/COUNT(num)
FROM (SELECT year, item1 AS item, num1 AS num FROM A
UNION ALL
SELECT year, item2 AS item, num2 AS num FROM A ) t
GROUP BY year, item
❹ sql 分類匯總 指定條件
selectDept,CC,SUM(Actual)as合計fromcActualwhereFiscalMonth<'P8'andFiscalYear='FY1314'
andFiscalMonthnotin('P7','P8')groupbyCC,Dept
這樣?
❺ SQL查詢結果分類匯總
SELECT A.*, COUNT(A.貨號) AS 貨號匯總, (A.規格匯總/ COUNT(A.貨號)) AS 比例 FROM
(
select GoodsNO as 貨號,GoodsName as 品名,SpecName as 規格,SUM(SellCount) as 規格匯總 from V_SSTTradeGoodsList where DateDiff(dd,Tradetime,getdate())<=30
GROUP BY GoodsNO,GoodsName,SpecName
)A
❻ sql分類匯總如何實現
select片區,客戶,產品名稱,sum(數量)frombiaogroupby片區,客戶,產品名稱
❼ sql分類查詢,分類匯總,查詢
selectrownumid,bianhao,fenleitj
from(
selectbianhao,count(1)asfenleitj
fromtab
groupbybianhao
havingcount(1)>1);
❽ sql如何實行多條件分類匯總
select item_no,sum(case receiptno when 'C01' then quantity else -1 * quantity end) as quantity ,sum(case receiptno when 'C01' then amount
else -1 * amount end ) amount
from table
group by item_no
❾ sql 分類匯總查詢語句
select dept as 部門,sum(pay) as 合計,sum(case zt when '01'then 1 else 0 end) as 個數(01狀態),
sum(case zt when '02'then 1 else 0 end) as 個數(02狀態),count(*) as 總數
from 表 group by dept
以上,希望對你有所幫助
❿ sql 分類匯總統計