SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Grouby giving dupes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

RammohanB
Starting Member

India
9 Posts

Posted - 11/30/2012 :  14:29:53  Show Profile  Reply with Quote
select SUM(A.price),B.bid,C.name from prices A
JOIN sal B ON B.id=A.id
JOIN persons C ON C.name= B.name
WHERE a.date = '2012-11-29'
group by bid,name
---
i am using above query but i am wrong values, i am getting sum(price) for the date for one id in one row . how can i get instead of two three rows to single row...i have multiple names having different ids but i need all ids prices in single row using name


Rammohan

shilpash
Yak Posting Veteran

90 Posts

Posted - 11/30/2012 :  14:40:39  Show Profile  Reply with Quote
SELECT SUM(A.price)
,B.bid
FROM prices A
JOIN sal B
ON B.id = A.id
WHERE a.date = '2012-11-29'
GROUP BY b.bid
Go to Top of Page

RammohanB
Starting Member

India
9 Posts

Posted - 11/30/2012 :  14:43:31  Show Profile  Reply with Quote
It worked thank you very much

Rammohan
Go to Top of Page

RammohanB
Starting Member

India
9 Posts

Posted - 11/30/2012 :  14:46:17  Show Profile  Reply with Quote
And also i want name too in my select list which is common in persons and bid

Rammohan
Go to Top of Page

shilpash
Yak Posting Veteran

90 Posts

Posted - 11/30/2012 :  15:25:27  Show Profile  Reply with Quote
WITH PriceCte
AS (SELECT SUM(A.price) price
,B.id
FROM prices A
JOIN sal B
ON B.id = A.id
WHERE a.date = '2012-11-29'
GROUP BY b.bid
)
SELECT p.person
,p.id
,t.price
FROM persons p
LEFT JOIN PriceCte T
ON T.id = p.id
Go to Top of Page

shilpash
Yak Posting Veteran

90 Posts

Posted - 11/30/2012 :  15:30:21  Show Profile  Reply with Quote
WITH PriceCte
AS (SELECT SUM(A.price) price
,B.id
FROM prices A
JOIN sal B
ON B.id = A.id
GROUP BY b.bid
)
SELECT p.person
,p.id
,t.price
FROM persons p
LEFT JOIN PriceCte T
ON T.id = p.id
WHERE P.date = '2012-11-29'

Edited by - shilpash on 11/30/2012 15:31:04
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000