在group by子句中获得问题

时间:2010-10-26 12:36:51

标签: sql sql-server sql-server-2000 group-by

我想从以下查询中获取数量总和。 我如何在下面提到的查询中编写group by子句。

select top 1 
EvrId,
TimeStamp,
Date,
BnhTnkMik1 as Quantity,
(select TnkCode from Tanklar where TnkId=BnhTnkId) as Tank,
FuelCode,
InvoiceNo from Evrak 
join Hareket on (BnhEvrId=EvrId)
join Stoklar on (StokId=BnhStok) 
where EvrTip=14 and EvrStatu='A'

2 个答案:

答案 0 :(得分:0)

select  
    EvrId,
    sum(BnhTnkMik1) as Quantity,
from Evrak 
join Hareket on (BnhEvrId=EvrId)
join Stoklar on (StokId=BnhStok) 
where EvrTip=14 and EvrStatu='A'
group by 
    EvrId

答案 1 :(得分:0)

select top 1 
  EvrId, 
  TimeStamp, 
  Date, 
  SUM(BnhTnkMik1) as Quantity, 
  (select TnkCode from Tanklar where TnkId=BnhTnkId) as Tank, 
  FuelCode, 
  InvoiceNo 
 from 
  Evrak 
  join Hareket on (BnhEvrId=EvrId)
  join Stoklar on (StokId=BnhStok)
  where EvrTip=14 and EvrStatu='A'
 GROUP BY 
  EvrId, 
  TimeStamp, 
  Date, 
  (select TnkCode from Tanklar where TnkId=BnhTnkId), 
  FuelCode, 
  InvoiceNo