group by中显示完全重复的项

2012-02-07 22:48

存在问题:
多表的联合查询SQL

解决方案:
今天晚上整了一晚上,总算把这问题解决了

原本代码为:
 select thby3,getkhname(thby3) name,thcpmc,to_char(thsjsl) thsjsl1,thccsj thccsj1,to_char(thsjsl*thccsj) money1,thch,count(0) as num from xsthd where thzt!='退货' and to_date(thzdrq,'yyyy-mm-dd hh24:mi:ss') between to_date('2012-02-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-02-07 23:59:59','yyyy-mm-dd hh24:mi:ss') and thcpmc='燃料甲醇' group by thby3, thsjsl,thccsj,thcpmc,thch union select distinct thby3,'总合计' name,'' thcpmc, to_char(sum(thsjsl)) thsjsl1,'' thccsj1, to_char(sum(thsjsl*thccsj)) money1,'' thch,0 as num from xsthd where thzt!='退货' and to_date(thzdrq,'yyyy-mm-dd hh24:mi:ss') between to_date('2012-02-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-02-07 23:59:59','yyyy-mm-dd hh24:mi:ss') and thcpmc='燃料甲醇' group by thby3 order by thby3 desc

查询结果为:
这里写图片描述

你可能感兴趣的:(软件类)