How to use sum() and group by [Resolved]

Posted by Oswaldlily under Sql Server on 3/7/2014 | Points: 10 | Views : 834 | Status : [Member] | Replies : 5
magno price date
13445A 45 20/09/2013
13445B 35 20/09/2013
13445C 10 20/09/2013

output shd be
134450 90(sum) 20/09/2013




Responses

Posted by: Bandi on: 3/7/2014 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
SELECT LEFT(magno, LEN(magno)-1)+ '0' as MagNo, date, SUM(price)
FROM TableName
GROUP BY LEFT(magno, LEN(magno)-1)+ '0', date


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Brahmam on: 3/7/2014 [Member] Starter | Points: 25

Up
0
Down
Hi
Please check this Query

select ID,sum(rate),date from mongo group by ID,date

brahmam

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 3/7/2014 [Member] Starter | Points: 25

Up
0
Down
now coming as..
magno price date
134450 90 20/09/2013
134450 90 20/09/2013
134450 90 20/09/2013

it shd come as single row like this
magno price date
134450 90 20/09/2013

all 3 magna number shd suppressed to "13445" and ends wit '0'
=> 134450...

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Brahmam on: 3/7/2014 [Member] Starter | Points: 25

Up
0
Down
yes...use this query it should came...same like as ur table

select magno,sum(price),date from tablename group by magno,price




brahmam

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saranpselvam on: 4/8/2014 [Member] Starter | Points: 25

Up
0
Down
select '134450' as mango ,sum([price]),[date] from tablename
group by [date]

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response