当前位置:首页 » 编程语言 » sqlcase子查询

sqlcase子查询

发布时间: 2023-02-24 23:39:44

㈠ SQL子查询统计

select
count(distinct(b.visit_id))'visit_id次数',

count(case when typeid=14 then 1 else 0)'14出现次数',
count(case when typeid=65 then 1 else 0)'65出现次数' from a
inner join b on a.visit_id=b.visitId

㈡ SQL子查询

select 用户名 ,所处大区, 所处省区,
sum(onty_cnt) as onty_cnt,sum(offty_cnt) as offty_cnt,
sum(overtime) as overtime
from
(select 用户名 ,所处大区, 所处省区, onty_time ,offty_time, 打卡日期,overtime,
case when to_char(onty_time,'hh24:mi') > '09:00' then 1 else 0 end as onty_cnt,
case when to_char(offty_time,'hh24:mi') < '17:20' then 1 else 0 end as offty_cnt
where 省区 = 参数
and 打卡日期 between '2009-01-01' and '2009-01-31' )
group by 用户名 ,所处大区, 所处省区

-------------------------------------
这是按人统计, 如果不要每个人的, 只要全部, 那就:

select 所处大区, 所处省区,
sum(onty_cnt) as onty_cnt,sum(offty_cnt) as offty_cnt,
sum(overtime) as overtime
from
(select 用户名 ,所处大区, 所处省区, onty_time ,offty_time, 打卡日期,overtime,
case when to_char(onty_time,'hh24:mi') > '09:00' then 1 else 0 end as onty_cnt,
case when to_char(offty_time,'hh24:mi') < '17:20' then 1 else 0 end as offty_cnt
where 省区 = 参数
and 打卡日期 between '2009-01-01' and '2009-01-31' )
group by 所处大区, 所处省区

-----------------------------
就是从外面的查询中把用户名去掉!
不明白HI我

热点内容
本地电脑怎么用服务器ip 发布:2025-07-01 09:10:03 浏览:827
有趣的python代码 发布:2025-07-01 09:10:02 浏览:357
威龙奇兵ftp 发布:2025-07-01 09:07:38 浏览:691
linuxedit 发布:2025-07-01 09:03:36 浏览:421
跑分平台脚本 发布:2025-07-01 08:40:17 浏览:599
手机上的中文编程软件 发布:2025-07-01 08:39:13 浏览:821
7z解压缩linux 发布:2025-07-01 08:37:47 浏览:320
sybase数据库字符集 发布:2025-07-01 08:37:03 浏览:348
php家教网 发布:2025-07-01 08:34:41 浏览:289
上传完毕声音 发布:2025-07-01 08:33:17 浏览:393