wudimj
风太冷
2018-08-21 00:41

SQL语句 两个表ORDER BY 两个字段,结果有问题

5
  • select
  • order by
  • sql

一个总表,一个详情表,总表的单位和详情表的品目一起做组队。但是最后的结果里面还是有单个的结果,最后我也count(1)>1了为什么还是会有单条的语句呢?

********SQL*******
select * from gfm_gp_purplan_bill T where exists(
select p.agency_code,d.pur_item_code,count(1),sum(d.amount),sum(p.amount) from gfm_gp_purplan_bill p left join gfm_gp_purplan_detail d on p.purplan_id=d.purplan_id
where p.pur_met_code!='1' and p.status>=4 and p.is_valid=1 and p.type<=3 and p.is_preyear=0 and p.amount group by p.agency_code,d.pur_item_code
having sum(p.amount)>=2000000 and count(1)>1

);

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答