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 分类汇总统计