开发环境:eclipse+struts1.2+hibernate
sql语句牵扯到3个表:Article,User,Dept。它们的字段分别为:
Article:id,passed,putoutPersonId(发布人id) //passed为1的时候表示审核通过
User:id,deptId,userName
Dept:id,deptName
表关系:
User表的主键id是Article表putoutPersonId的外键。Dept表的主键id是User表deptId的外键。
请分别用Hql和sql完成以下要求:
1.查看所有部门或某部门文章(Article)的发布总数,通过总数,未通过总数。
2.查看所有或某一发布人发布文章的总数、通过总数、未通过总数。
在此谢过大家!
sql语句牵扯到3个表:Article,User,Dept。它们的字段分别为:
Article:id,passed,putoutPersonId(发布人id) //passed为1的时候表示审核通过
User:id,deptId,userName
Dept:id,deptName
表关系:
User表的主键id是Article表putoutPersonId的外键。Dept表的主键id是User表deptId的外键。
请分别用Hql和sql完成以下要求:
1.查看所有部门或某部门文章(Article)的发布总数,通过总数,未通过总数。
2.查看所有或某一发布人发布文章的总数、通过总数、未通过总数。
在此谢过大家!
解决方案 »
- 求一段时间
- 求sql语句将数据库表某些字段的内容翻10倍
- 关于事务和触发器的问题,请高手指教!
- oracle错误的问题(在线急等)
- 江湖救急,问题很少见!关于一个merge语句?帮忙up有分,谢谢了!
- 高手帮我看一下,这个存储过程为什么编译通不过?
- 如何用create table建立一张表时,同时指定表空间?
- 通过培训学unix oracle好吗?请教!在北京,哪的培训机构比较好!
- http://download.oracle.com/otn/utilities_drivers/odbc/oracle9i/ora9202.exe
- mysql语句脚本转成 oracle 求办法?
- 求救!执行存储过程出现pls-00103错误。在线等候答案
- 这个sql怎么优化?
Article:id,passed,putoutPersonId(发布人id) //passed为1的时候表示审核通过
User:id,deptId,userName
Dept:id,deptName
1.查看所有部门或某部门文章(Article)的发布总数,通过总数,未通过总数。
2.查看所有或某一发布人发布文章的总数、通过总数、未通过总数。
*/
1.查看所有部门或某部门文章(Article)的发布总数,通过总数,未通过总数。
select c.id
count(a.id),
count(case when passed=1 then 1 else 0 end),
count(case when passed=0 then 1 else 0 end)
from
article a,
user b,
dept c
where a.putoutPersonId=b.id(+) and a.id=c.id(+)
group by c.id
--如果是某个部门 and c.id='???'
2.查看所有或某一发布人发布文章的总数、通过总数、未通过总数。
同上
1.查看所有部门或某部门文章(Article)的发布总数,通过总数,未通过总数。
select deptname,count(*) as 发布总数,
sum(decode(passed,1,1,0)) as 通过总数,
sum(decode(passed,0,1,0)) as 未通过总数
from article,dept,usern where article.putoutPersonId=user.id and user.deptid=dept.id
group by deptname
select b.deptname,count(*) as 发布总数,
sum(case when a.passed=1 then 1 else 0 end) as 通过总数,
sum(case when a.passed=0 then 1 else 0 end) as 未通过总数
from article a,dept b,user c
where a.putoutPersonId=c.id and c.deptid=b.id
group by b.deptname2.查看所有或某一发布人发布文章的总数、通过总数、未通过总数。
select c.id,count(*) as 发布总数,
sum(case when a.passed=1 then 1 else 0 end) as 通过总数,
sum(case when a.passed=0 then 1 else 0 end) as 未通过总数
from article a,dept b,user c
where a.putoutPersonId=c.id and c.deptid=b.id
group by c.id