当前位置:首页 » 编程语言 » sql多列数据统计
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql多列数据统计

发布时间: 2022-05-02 22:40:42

sql统计一个表的多列

我在机器上面试验过了,下面的语句没有问题,不过你需要修改一下表名,列名以及那几个特殊字符。 应该可以满足你的要求了。
我用的表:
a1
a2
a3
a4
a5
b1
b2
b3
b4
b5
c1
c2
c3
c4
c5

结果:
a 5
b 5
c 5
select t, count(t)
from (select case
when instr(name, 'a') != 0 then
'a'
when instr(name, 'b') != 0 then
'b'
when instr(name, 'c') != 0 then
'c'
else
'other'
end t
from leo) a
group by t;

② sql如何进行多个字段的统计个数

一种查询SQL如下, 利用union获得b和c各自的统计结果, 然后再一次统计整合到最终结果:

selectsum(d.b_cnt)+sum(d.c_cnt)astotal_cnt,sum(d.b_cnt)asb_cnt,casewhensum(d.b_cnt)=0then''elsed.valendasb_label,sum(d.c_cnt)asc_cnt,casewhensum(d.c_cnt)=0then''elsed.valendasc_labelfrom(selectbasval,count(b)asb_cnt,0asc_,0,count(c)asc_cntfromAgroupbyc)dgroupbyd.val

SQLSerer上的测试结果(栏位次序有变化),

total_cnt为总数, b_label为b栏值, b_cnt为b栏个数, c_labe为c栏值, c_cnt为c栏个数.

这个结果跟字段是否为整型无关, 它是统计记录出现的次数.

③ sql语句如何实现实现查询多列的数据

可以,我看Id列应该是唯一的吧。根据proctID分组的时候,取max(id),然后通过此id关联,就可以把其他列数据也查询出来了

④ sql 多列统计

select你要分别查的工号,count(1)from表groupby你要分别查的工号

比如select检查工号,核对工号,申请工号,count(1)from表groupby检查工号,核对工号,申请工号

或者你是要这样的

SELECT检查工号,核对工号,申请工号,
COUNT(1)OVER(PARTITIONBY检查工号),
COUNT(1)OVER(PARTITIONBY核对工号),
COUNT(1)OVER(PARTITIONBY申请工号)
FROM表

⑤ 一条sql语句同时统计两列的数据

给你举个例子吧,比如有个表TABLE_,表里有3列:
t_id t_1 t_2
1 1 10
2 2 20
3 3 30
4 4 40
5 5 50

要计算t_1列前3个之和,t_2列前5个之和

select sum(a.t_1),sum(b.t_2) from table_ as a left join table_ as b on a.t_id=b.t_id and b.t_id<=5
where a.t_id<=3

⑥ sql多列统计

嗯嗯嗯
select x as col001 ,count(x) as col002 from
(select a as x from table1
union all
select b as x from table1
union all
select c as x from table1
union all
select d as x from table1
) group by x