首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >s_p的组合3查询

s_p的组合3查询
EN

Stack Overflow用户
提问于 2013-09-14 07:28:08
回答 2查看 35关注 0票数 0
代码语言:javascript
复制
select Month(user_lastlogin) as Month,year(user_lastlogin) as Year,
count(*) as 'Total             Reg' from bb_user 
group by Month(user_lastlogin),year(user_lastlogin)
order by  Month desc

select count(*) as 'LR Reg' from bb_user 
where  user_regtype ='LR'
group by Month(user_lastlogin)
order by  Month desc

select count(*) as 'BBR Reg' from bb_user 
where  user_regtype is null OR user_regtype = 'BBR'
group by Month(user_lastlogin)
order by  Month desc

我想显示为月/年/总注册/LR Reg/BBR Reg

我在三个不同的查询中删除结果,但我想在一个查询中编写存储过程....means,我想在第一个查询中添加第二个和第三个查询。

user_lastlogin = RegistrationDatetime

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-14 07:39:24

你在找这样的东西吗?

代码语言:javascript
复制
SELECT MONTH(user_lastlogin) AS Month,
       YEAR(user_lastlogin) AS Year,
       COUNT(*) AS 'Total Reg',
       SUM(CASE WHEN user_regtype = 'LR' THEN 1 ELSE 0 END) AS 'LR Reg',
       SUM(CASE WHEN IS NULL OR user_regtype = 'BBR' THEN 1 ELSE 0 END) AS 'BBR Reg'
  FROM bb_user 
GROUP BY MONTH(user_lastlogin), YEAR(user_lastlogin)
ORDER BY Year DESC, Month DESC
票数 0
EN

Stack Overflow用户

发布于 2013-09-14 07:39:40

你的解释很不清楚,但我认为这是你实际上想要的。

代码语言:javascript
复制
select
  Month(user_lastlogin) as Month,
  year(user_lastlogin) as Year,
  count(*) as [Total Reg],
  SUM(CASE WHEN user_regtype ='LR' THEN 1 END) [LR Reg],
  SUM(CASE WHEN user_regtype is null OR user_regtype = 'BBR THEN 1 END) [BBR Reg]
from bb_user 
group by
  Month(user_lastlogin),
  year(user_lastlogin)
order by  Month desc
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18799418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档