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

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Group by data

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-10-15 : 06:14:42
I have data where i want to use a group by.
But i have columns where i can't group by they are the serial numbers and total price as they are different values in each field all other data has the same data so i can use the group by how do i get around the others ?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-10-15 : 06:26:52
If you don't want to group by serial numbers, you'll have to leave them out of your query. As for the price, could you use SUM(price)?

Jim
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-15 : 07:19:09
Can you post some sample data with expected result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-10-15 : 08:26:44
Here is my test data,

VOUCHER_ID CONTRACT_ID [Date] TOTAL_PRICE SERIAL_ID
12016010 840376 2007-10-09 69 3830195652
12016010 840376 2007-10-09 56 3830141153

i like to Group by on all the columns and get a max date
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-15 : 08:58:16
SELECT t.Voucher_ID, t.Contract_ID, t.[Date], t.Total_Price, t.Serial_ID
FROM Table1 AS t
WHERE t.Serial_ID = (SELECT TOP 1 r.Serial_ID FROM Table1 AS r WHERE r.Voucher_ID = t.Voucher_ID AND r.Contract_ID = t.Contract_ID ORDER BY r.[Date] DESC, r.Total_Price DESC, r.Serial_ID DESC)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -