|
假设你的表叫 TEL
语句为:
SELECT tp1.日期, tp1.总通话量, tp2.拨入电话, tp3.拨出电话
FROM
( SELECT DATE(t1.插入时间) as 日期, count(t1.id) as 总通话量 FROM TEL t1
WHERE t1.插入时间 > '2007-11-01 00:00:00' AND t1.插入时间 < '2007-12-01 00:00:00'
GROUP BY DATE(t1.插入时间) ) tp1,
( SELECT DATE(t2.插入时间) as 日期, count(t2.id) as 拨入电话 FROM TEL t2
WHERE t2.插入时间 > '2007-11-01 00:00:00' AND t2.插入时间 < '2007-12-01 00:00:00' AND t2.通话类型 = '拨入'
GROUP BY DATE(t2.插入时间) ) tp2,
( SELECT DATE(t3.插入时间) as 日期, count(t3.id) as 拨出电话 FROM TEL t3
WHERE t3.插入时间 > '2007-11-01 00:00:00' AND t3.插入时间 < '2007-12-01 00:00:00' AND t3.通话类型 = '拨出'
GROUP BY DATE(t3.插入时间) ) tp3
WHERE tp1.日期 = tp2.日期 and tp1.日期 = tp3.日期 ;
这种写法效率是个问题,结果集如果很大的话,会很慢的。希望对你有帮助。
[ 本帖最后由 edwin_chen 于 2007-11-6 17:46 编辑 ] |
|