❶ 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
这样?