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.
| Author |
Topic |
|
Flaterik
Starting Member
26 Posts |
Posted - 2012-12-18 : 04:59:12
|
| Hi people i have a table with this dataCd_CF Cd_Ar Datadoc PriceFor ExampleCd_CF Cd_Ar Datadoc PriceA0000 C1111 13/12/2012 231 A0000 C1111 13/11/2012 231 A0000 C1111 21/12/2012 90A0000 C3333 21/12/2012 96A0010 C1111 13/12/2012 65A0010 B2222 13/12/2012 78What i must have is For Each CD_CF , the CD_AR with MAX Datadoc. But not only 1 Cd-AR , all the CD_ar but if is duplicated, only one with max datadoc.Thanks************************************************the world is strange but people are crazy |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-18 : 05:18:18
|
SELECT Cd_CF, Cd_Ar, MAX(datadoc)FROM @tab1GROUP BY Cd_CF, Cd_ArIf you want to display last product details along with price per each client,SELECT t1.* FROM @tab1 t1JOIN (SELECT Cd_CF, Cd_Ar, MAX(datadoc) maxxFROM @tab1GROUP BY Cd_CF, Cd_Ar) t2ON t1.Cd_Ar = t2.Cd_Ar AND t1.Cd_CF = t2.Cd_CF AND t1.Datadoc = t2.maxx --Chandu |
 |
|
|
Flaterik
Starting Member
26 Posts |
Posted - 2012-12-18 : 06:38:35
|
| Nice, thank you very much************************************************the world is strange but people are crazy |
 |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-18 : 06:42:25
|
quote: Originally posted by Flaterik Nice, thank you very much
you are Welcome --Chandu |
 |
|
|
|
|
|