![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a table with three columns: Name Date Action Fred Today this Fred Today this Fred Today that Wilma Today this I want to sort by name and by date, but only if 'this' was done more than once on the same day, and not if 'that' was done on the same day,They have to perform this more than once, and they cannot have performed that on the same day. Thanks, Harry |
#3
| |||
| |||
|
|
Now what possible actions might this/that be? This: drive to bowling alley That: Feed Dino Looks very much like a homework assignment to me... Harry schreef op 23-08-2011 15:49: I have a table with three columns: Name * * * * Date * * * * * Action Fred * * * * * Today * * * * this Fred * * * * * Today * * * * this Fred * * * * * *Today * * * *that Wilma * * * * Today * * * * this I want to sort by name and by date, but only if 'this' was done more than once on the same day, and not if 'that' was done on the same day,They have to perform this more than once, and they cannot have performed that on the same day. Thanks, Harry |
#4
| |||
| |||
|
|
I have a table with three columns: Name Date Action Fred Today this Fred Today this Fred Today that Wilma Today this I want to sort by name and by date, but only if 'this' was done more than once on the same day, and not if 'that' was done on the same day,They have to perform this more than once, and they cannot have performed that on the same day. So the desired result from this sample data would be an empty resultset? |
#5
| |||
| |||
|
|
Harry wrote: I have a table with three columns: Name * * * * Date * * * * * Action Fred * * * * * Today * * * * this Fred * * * * * Today * * * * this Fred * * * * * *Today * * * *that Wilma * * * * Today * * * * this I want to sort by name and by date, but only if 'this' was done more than once on the same day, and not if 'that' was done on the same day,They have to perform this more than once, and they cannot have performed that on the same day. So the desired result from this sample data would be an empty resultset? What do you want to display when the data actually contains rows that meet your requirement? All the rows for that name and date? Or a single row for that name and date? Why don't you try again. Show us some sample data that includes data that meets your requirements and then show us what you want the desired query to return. The key being "show" - don't just describe the desired result: show it to us. |
#6
| |||
| |||
|
|
On Aug 23, 2:11 pm, "Bob Barrows" <reb01... (AT) NOyahooSPAM (DOT) com> wrote: Harry wrote: I have a table with three columns: Name Date Action Fred Today this Fred Today this Fred Today that Wilma Today this I want to sort by name and by date, but only if 'this' was done more than once on the same day, and not if 'that' was done on the same day,They have to perform this more than once, and they cannot have performed that on the same day. So the desired result from this sample data would be an empty resultset? What do you want to display when the data actually contains rows that meet your requirement? All the rows for that name and date? Or a single row for that name and date? Why don't you try again. Show us some sample data that includes data that meets your requirements and then show us what you want the desired query to return. The key being "show" - don't just describe the desired result: show it to us. The raw data would be: Name Date Proc Fred 1 stent Fred 1 stent Fred 1 unstent Wilma 2 stent Wilma 2 stent Barney 2 stent Barnet 2 stent Barney 2 stent Barney 2 unstent ... The query would return Wilma 2 stent Wilma 2 stent Because Fred and Barney also had a stent pulled on the same day they had more than one stent inserted. Assuming SQL 2005 or greater: |
#7
| |||
| |||
|
|
Not a homework question. Clinical research. A patient may have one or more stents inserted during a procedure. He may also have a stent taken out. I am looking for patients who had more than one stent inserted during a procedure, and who did not have a stent taken out during the same procedure. harry |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
select * from t1 where proc = 'stent' and (name, date) in ( select name,date from t1 group by name,date having count(distinct proc) = 1 ) |
#10
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |