Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 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
Posting Yak Master

103 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
Posting Yak Master

103 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
Posting Yak Master

103 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  
 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.69 seconds. Powered By: Snitz Forums 2000