当前位置:首页 » 编程语言 » 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-07-01 13:32:06 浏览:763
c语言表达式绝对值 发布:2025-07-01 13:25:45 浏览:489
获取网站访问量 发布:2025-07-01 13:20:28 浏览:291
平行线算法 发布:2025-07-01 13:10:13 浏览:601
c语言不可嵌套的是 发布:2025-07-01 13:04:33 浏览:328
三星手机老是显示存储空间不足 发布:2025-07-01 13:00:09 浏览:594
ewebeditor上传漏洞 发布:2025-07-01 13:00:08 浏览:836
电脑无解压 发布:2025-07-01 12:51:18 浏览:732
中国股票市场交易数据库 发布:2025-07-01 12:43:23 浏览:622
oppoa37怎么给应用加密 发布:2025-07-01 12:20:53 浏览:644