IT也有一段時間了,剛開始的時候``````
的困難主要是在編程語言上,數(shù)組,邏輯,算法,...
這些都過來了之后,困難就上升到數(shù)據(jù)庫設(shè)計上了.
以及數(shù)據(jù)邏輯.
一個優(yōu)秀的系統(tǒng),會集成優(yōu)秀的程序和優(yōu)秀的數(shù)據(jù)庫設(shè)計.
要做到這點得有足夠的經(jīng)驗.
這是我寫的一個結(jié)合UINON的嵌套查詢.
將五個方面的報表放到一個臨時表里,再從臨時表里,將所要的數(shù)據(jù)查詢出來.
復(fù)制代碼 代碼如下:
$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嵌套查詢和聯(lián)表查詢優(yōu)化方法
- 單個select語句實現(xiàn)MySQL查詢統(tǒng)計次數(shù)
- sql查詢出各科成績最好的學(xué)生信息
- mysql查詢昨天 一周前 一月前 一年前的數(shù)據(jù)
- mysql查詢今天、昨天、近7天、近30天、本月、上一月的SQL語句
- MySql查詢時間段的方法
- php+mysql查詢優(yōu)化簡單實例
- MySQL查詢和修改auto_increment的方法
- 一個優(yōu)化MySQL查詢操作的具體案例分析
- MySQL查詢倒數(shù)第二條記錄實現(xiàn)方法
- 50條SQL查詢技巧、查詢語句示例
- SQL查詢出表、存儲過程、觸發(fā)器的創(chuàng)建時間和最后修改時間示例
- 大幅優(yōu)化MySQL查詢性能的奇技淫巧
- 如何使用MySQL查詢某個列中相同值的數(shù)量統(tǒng)計
- 數(shù)據(jù)庫表的查詢操作(實驗二)