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
 SQL Server Development (2000)
 Tough query

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 Buffcode18
My brain must be not working when i initilally post this
[edit]
select count(distinct [user id])
from yourtable t
where type = 62
and not exists (select * from yourtable x
where 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
Go to Top of Page

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.

DavidM

Intelligent Design is NOT science.

A front-end is something that tries to violate a back-end.
Go to Top of Page

Buffcode18
Starting Member

2 Posts

Posted - 2005-12-19 : 13:05:22
Figured it out...

select count(*)
from tbl
where type = 62
and user_id not in
(select user_id
from tbl
where type in (63,64,65,67))
Go to Top of Page
   

- Advertisement -