请大神帮忙检查一下语句有没有什么问题,查出来的结果不是很满意

chinabdx 2015-12-21 04:14:16
select A.gdssalecode as '商品编码',
A.printprice as '价格',
SUM(A.pamount) as '打印数量'
from inf_gdscode B,
inf_supplier C,
(select a.gdssalecode as gdssalecode,
a.printprice as printprice,
a.pamount as pamount
from (select gdssalecode,
printprice,
SUM(printamount) as pamount
from sys_labelprint_log
where printdate >= '2015-11-01'
and printdate <= '2015-11-30'
group by gdssalecode,printprice) a
left join (select gdssalecode,saleprice
from inf_salecode) b on a.gdssalecode = b.gdssalecode
left join (select gdssalecode,oldsaleprice
from bil_changedtl
group by gdssalecode,oldsaleprice) c on a.gdssalecode = c.gdssalecode
where a.printprice <> b.saleprice
and a.printprice <> c.oldsaleprice
group by a.gdssalecode,
a.printprice,
a.pamount) A
where B.suppliercode = C.suppliercode
and B.gdscode = LEFT(A.gdssalecode,8)
and B.suppliercode = '101510'
group by A.gdssalecode,
A.printprice
order by A.gdssalecode


商品编码 价格 数量
1201009400 6.00 1 这条记录应该是过滤的记录,属于C.oldsaleprice这列数据的记录
1201010900 17.00 2
1201014800 21.60 1
1201014800 30.00 1
1201019000 16.00 1
1201024200 12.00 2
...全文
110 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tiger_Zhao 2015-12-21
  • 打赏
  • 举报
回复
        left join (select gdssalecode,saleprice
from inf_salecode) b on a.gdssalecode = b.gdssalecode
/* 这一段去掉
left join (...) c on a.gdssalecode = c.gdssalecode
*/
where a.printprice <> b.saleprice
/* 变成下面的条件 */
and NOT EXISTS (select *
from bil_changedtl c
WHERE c.oldsaleprice = a.printprice
AND c.gdssalecode = a.gdssalecode)
chinabdx 2015-12-21
  • 打赏
  • 举报
回复
的确是有多个,如何将这个表里面同一个商品编码的多个记录都同时过滤掉
Tiger_Zhao 2015-12-21
  • 打赏
  • 举报
回复
看你的命名 bil_changedtl 是一个明细表,所以很可能 gdssalecode = 1201009400 下面有多个不同的 oldsaleprice,至少其中有一条不等于 6.00。

22,301

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧