當前位置:首頁 » 編程語言 » 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 20:52:56 瀏覽:159
解壓放鬆室 發布:2025-07-01 20:52:43 瀏覽:124
存儲器壞了 發布:2025-07-01 20:46:11 瀏覽:510
iphone怎麼設鎖屏密碼 發布:2025-07-01 20:46:10 瀏覽:620
伺服器如何處理千萬請求 發布:2025-07-01 20:30:53 瀏覽:332
plsqldeveloperjob 發布:2025-07-01 20:29:59 瀏覽:803
剪切文件用什麼配置 發布:2025-07-01 20:23:07 瀏覽:41
酷睿2020主要看哪些配置 發布:2025-07-01 20:23:06 瀏覽:259
sql保存文件 發布:2025-07-01 20:18:52 瀏覽:802
安卓做的登錄頁面怎麼運行 發布:2025-07-01 20:18:48 瀏覽:813