删除SQL重复值,明显不起作用

时间:2015-03-21 04:49:37

标签: sql unique distinct nexusdb

SELECT BM.PUser, 
   BM.Desc, BM.Price, 
   BM.Info,
   CAST (CASE 
      WHEN BI.Closed = 'E' then BQ.Qty-BQ.Consign-(SUM(BD.QtySold))
      ELSE BQ.Qty-BQ.Consign
   END as int) as Stock
FROM BINVOICE BI
 , BDETAIL BD
 , BQTY BQ
 , BMASTER BM
WHERE (BD.User = BI.User)
   AND 
  (BQ.PartNo = BD.PartNo)
   AND
  (BQ.PartNo = BM.PartNo)
   AND
  (BM.Price > 0.01)
   AND
  (BM.Active = 'Y')
GROUP BY BM.PUser, BM.Price,
     BM.Desc, BM.Info, 
     BQ.Consign, BQ.Qty,
     BI.Closed

我的问题是我只希望显示每个PUser中的一个,但其中一些会出现多次。我相信我所做的案例就是他们来自哪里。我不太清楚如何解决这个问题。使用SELECT DISTINCT对我不起作用。任何指导将不胜感激。它用于NexusDB。

1 个答案:

答案 0 :(得分:0)

使用与众不同 SELECT DISTINCT column_name,column_name FROM table_name;

SELECT Distinct  BM.PUser, 
   BM.Desc, BM.Price, 
   BM.Info,
   CAST (CASE 
      WHEN BI.Closed = 'E' then BQ.Qty-BQ.Consign-(SUM(BD.QtySold))
      ELSE BQ.Qty-BQ.Consign
   END as int) as Stock
FROM BINVOICE BI
 , BDETAIL BD
 , BQTY BQ
 , BMASTER BM
WHERE (BD.User = BI.User)
   AND 
  (BQ.PartNo = BD.PartNo)
   AND
  (BQ.PartNo = BM.PartNo)
   AND
  (BM.Price > 0.01)
   AND
  (BM.Active = 'Y')
GROUP BY BM.PUser, BM.Price,
     BM.Desc, BM.Info, 
     BQ.Consign, BQ.Qty,
     BI.Closed