views:

37

answers:

2

hi friends,

i want to get the sum of quantity from the below query. how i write the group by clause in below mention query.

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'
A: 
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
Martin
thank u,but i am getting the same data as i m previously getting
gofor.net
@gorfor.net - You need to be more specific in your question. What would you like the sum of? The EvrId, or some other column?
Martin
A: 
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 
Andy Evans
thanks for replybut i m getting th following error after executionCannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause.
gofor.net