当前位置:首页 » 编程语言 » 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我

热点内容
安卓手机下载软件在哪里设置密码 发布:2025-09-18 20:10:08 浏览:600
net业务缓存框架 发布:2025-09-18 19:57:14 浏览:6
pythonrst 发布:2025-09-18 19:28:50 浏览:405
页面访问在线升级 发布:2025-09-18 19:13:46 浏览:773
相机存储满 发布:2025-09-18 19:12:19 浏览:755
如何搭载我的世界服务器 发布:2025-09-18 19:02:39 浏览:427
c语言组框 发布:2025-09-18 19:02:23 浏览:943
如何看见真我手机的全部配置 发布:2025-09-18 18:48:10 浏览:976
战地5默认是什么服务器 发布:2025-09-18 17:59:32 浏览:311
安卓变ios系统主题怎么弄 发布:2025-09-18 17:54:07 浏览:889