利用SQL语句进行分类汇总的问题,进来看看
3个回答
展开全部
假设user_id为PK,如果离职时间(out_date)为空表示未在职。
下列的代码分别统计:员工纪录总数、在职人数、离职人数。
select count(*) as inoutAll,
sum( case when out_date is null then 1
else 0
end ) as inSum,
sum( case when out_date is not null then 1
else 0
end ) as ouSum
from bob_c_sec_user
下列的代码分别统计:员工纪录总数、在职人数、离职人数。
select count(*) as inoutAll,
sum( case when out_date is null then 1
else 0
end ) as inSum,
sum( case when out_date is not null then 1
else 0
end ) as ouSum
from bob_c_sec_user
展开全部
假设离职日期字段为null表示未离职
select
(select count(*) from zhigong where ruzhiriqi is not null and lizhiriq is null) as ruzhicount,
(select count(*) from zhigong where lizhiriq is not null) as lizhicount
select
(select count(*) from zhigong where ruzhiriqi is not null and lizhiriq is null) as ruzhicount,
(select count(*) from zhigong where lizhiriq is not null) as lizhicount
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以用两个sql语句分别count出两个的总数,再将两个值合到一起
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询