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 |
|
Buffcode18
Starting Member
2 Posts |
Posted - 2005-12-18 : 19:09:46
|
| Here's what I'm trying to do-I'm running a few different contests, and keeping track of who is entering each one.I have a table which logs a user id, the date entered, and a type code for which contest. I want to find out how many people have submitted to contest 62 who have not subscribed to any of the other contests (63, 64, and 65). Can't figure out a query? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-12-18 : 19:41:48
|
Welcome to SQLTeam Buffcode18My brain must be not working when i initilally post this[edit]select count(distinct [user id])from yourtable twhere type = 62and not exists (select * from yourtable xwhere x.[user id] = t.[user id]and type in (63, 64, 65)) [/edit]Note the count distinct to obtain the number of unique user id-----------------[KH]Learn something new everyday |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2005-12-18 : 19:53:55
|
| That won't work.You are after a form of relational division. Look it up. If you are still struggling, post again.DavidMIntelligent Design is NOT science.A front-end is something that tries to violate a back-end. |
 |
|
|
Buffcode18
Starting Member
2 Posts |
Posted - 2005-12-19 : 13:05:22
|
| Figured it out...select count(*) from tblwhere type = 62and user_id not in (select user_id from tbl where type in (63,64,65,67)) |
 |
|
|
|
|
|
|
|