❶ sql分類匯總
select sum(數量), 編碼
from table
group by 編碼
❷ SQL按使用分類匯總
select distinct(部門),(select sum(金額) from 表 where 類別=a) as a,(select sum(金額) from 表 where 類別=b) as b,(select sum(金額) from 表 where 類別=c) as c from 表
❸ 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條件分類匯總
只會點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分類匯總如何實現
select片區,客戶,產品名稱,sum(數量)frombiaogroupby片區,客戶,產品名稱
❻ 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如何按天和類別分類匯總
selectconvert(varchar(10),a.rq,120),B,isnull(count(*),0)
(select
cast('2014-01-10'asdatetime)+number-1rq
frommaster..spt_valueswheretype='P'andnumberbetween1and(selectdatediff(day,cast('2014-01-10'asdatetime),cast('2014-01-13'asdatetime)))+1)asa
leftjoinTbNamebonconvert(varchar(10),a.rq,120)=convert(char(10),b.A,120)
groupbyconvert(varchar(10),a.rq,120),B
這樣試試
主要是你把這句弄懂了就行,用這個構造一個時間的虛擬列
select
cast('2014-01-10'asdatetime)+number-1rq
frommaster..spt_valueswheretype='P'andnumberbetween1and(selectdatediff(day,cast('2014-01-10'asdatetime),cast('2014-01-13'asdatetime)))+1
❽ sql分類匯總
將幾張表聯合查詢,這樣出來的數據看上去就是一樣表
然後將這張表按照你的唯一IDgroup by,sum函數求和你的金額,積分等
❾ sql 命令 按名字分類匯總
select userid,count(*) as 發表數 from 表 group by userid
❿ sql 分類匯總 指定條件
selectDept,CC,SUM(Actual)as合計fromcActualwhereFiscalMonth<'P8'andFiscalYear='FY1314'
andFiscalMonthnotin('P7','P8')groupbyCC,Dept
這樣?