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 |
|
tapas16880
Starting Member
2 Posts |
Posted - 2012-06-28 : 04:02:29
|
| I have got a table like below:Order No Name Amt100 ABC 50100 DEF 40200 ABC 80300 FRC 44300 SDE 90 400 ABC 200500 EWQ 40500 QWE 50I want to retrieve the records where the NAME is "ONLY" ABC i.e. there will be one record for that order no where the name is ABCSo, the result should give me: Order No Name Amt200 ABC 80400 ABC 200Can you please tell me how to write an efficient query to get this result? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-06-28 : 04:47:28
|
SELECT [Order No], Name, AmtFROM (SELECT *, COUNT(*) OVER (PARTITION BY [Order No]) AS cnt FROM dbo.Table1) AS dWHERE cnt = 1 AND Name = 'ABC' N 56°04'39.26"E 12°55'05.63" |
 |
|
|
tapas16880
Starting Member
2 Posts |
Posted - 2012-06-28 : 05:52:27
|
| Thanks but it doesn't work as I use SAS Enterprise Guide and use PROC SQL to run the queries. It didn't recognise OVER (PARTITION BY) clause. I tried removing this but still didn't work(the query finished but no data). |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-06-29 : 08:37:27
|
This is a Microsoft SQL Server forum.Try your luck over at www.dbforums.com N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|