IT也有一段时间了,刚开始的时候``````
的困难主要是在编程语言上,数组,逻辑,算法,...
这些都过来了之后,困难就上升到数据库设计上了.
以及数据逻辑.
一个优秀的系统,会集成优秀的程序和优秀的数据库设计.
要做到这点得有足够的经验.
这是我写的一个结合UINON的嵌套查询.
将五个方面的报表放到一个临时表里,再从临时表里,将所要的数据查询出来.
复制代码 代码如下:
$sql="SELECT type , sum( yjsl ) as yjsl , sum( yysl ) as yysl, sum( jyrs ) as jyrs, sum( jycs ) as jycs
FROM (
SELECT c.mc AS
TYPE , count( d.lsh ) AS yjsl, 0 AS yysl, 0 AS jyrs, 0 AS jycs
FROM sys_dzxxb AS b, sys_jcb AS c, sys_dzyjb AS d
WHERE b.bm = c.lsh
AND d.dzlsh = b.lsh
GROUP BY c.mc
UNION SELECT c.mc AS
TYPE , 0 AS yjsl, count( e.lsh ) AS yysl, 0 AS jyrs, 0 AS jycs
FROM sys_dzxxb AS b, sys_jcb AS c, sys_dzyy AS e
WHERE b.bm = c.lsh
AND e.dzlsh = b.lsh
GROUP BY c.mc
UNION SELECT c.mc AS
TYPE , 0 AS yjsl, 0 AS yysl, count( DISTINCT e.dzlsh ) AS jyrs, 0 AS jycs
FROM sys_dzxxb AS b, sys_jcb AS c, sys_ltxxb AS e
WHERE b.bm = c.lsh
AND e.dzlsh = b.lsh
GROUP BY c.mc
UNION SELECT c.mc AS
TYPE , 0 AS yjsl, 0 AS yysl, 0 AS jyrs, count( DISTINCT e.lsh ) AS jycs
FROM sys_dzxxb AS b, sys_jcb AS c, sys_ltxxb AS e
WHERE b.bm = c.lsh
AND e.dzlsh = b.lsh
GROUP BY c.mc
) AS temptable
GROUP BY TYPE ";
分享给大家.
您可能感兴趣的文章:- mysql嵌套查询和联表查询优化方法
- 单个select语句实现MySQL查询统计次数
- sql查询出各科成绩最好的学生信息
- mysql查询昨天 一周前 一月前 一年前的数据
- mysql查询今天、昨天、近7天、近30天、本月、上一月的SQL语句
- MySql查询时间段的方法
- php+mysql查询优化简单实例
- MySQL查询和修改auto_increment的方法
- 一个优化MySQL查询操作的具体案例分析
- MySQL查询倒数第二条记录实现方法
- 50条SQL查询技巧、查询语句示例
- SQL查询出表、存储过程、触发器的创建时间和最后修改时间示例
- 大幅优化MySQL查询性能的奇技淫巧
- 如何使用MySQL查询某个列中相同值的数量统计
- 数据库表的查询操作(实验二)