一个很难的问题,大神来回答吧

XuePengcn 2013-07-11 08:10:14


这是源数据,根据不同的adminid,算出每个adminid有多少条数据,并且state为0的有几条,为1的有几条
返回结果是这样的:

adminid total state0 state1
1 100 90 10
2 111 55 56
total是state的总数,state0是state=0的数量,state1是state=1的数量,adminid是adminid


然后将以下得到的数据全部插入表2内:

表2字段为:

adminid s_total s_state0 s_state1

请教各位大神如何做了?
...全文
69 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Regan-lin 2013-07-11
  • 打赏
  • 举报
回复
这到底有多难,我倒是没看出来
ACMAIN_CHM 2013-07-11
  • 打赏
  • 举报
回复
引用 2 楼 rucypli 的回复:
insert into tb2 select adminid,count(*) as total, count(case when state=0 then 1 end) as state0, count(case when state=1 then 1 end) as state1 from tb group by adminid
+1
rucypli 2013-07-11
  • 打赏
  • 举报
回复
insert into tb2 select adminid,count(*) as total, count(case when state=0 then 1 end) as state0, count(case when state=1 then 1 end) as state1 from tb group by adminid
rucypli 2013-07-11
  • 打赏
  • 举报
回复
select adminid,count(*) as total, count(case when state=0 then 1 end) as state0, count(case when state=1 then 1 end) as state1 from tb group by adminid

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧