Re: select query assistance
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 07 Apr 2005 23:00:01 +0200
On Thu, 7 Apr 2005 13:13:03 -0700, AshleyT wrote:
>thanks Hugo.
>
>What you wrote gets me the lines that are Department = 2.
Hi Ashley,
Did you test it?
Using your sample data and a greatly simplified table declaration (no
keys, etc):
create table YourTable (Ticket int, date datetime, ordinal int,
department int)
go
insert YourTable
select 01 , '20050101', 1 , 2 union all
select 01 , '20050101', 2 , 2 union all
select 02, '20050101', 1 , 3 union all
select 02, '20050101', 2 , 2
go
-- My first query
SELECT *
FROM YourTable AS a
WHERE NOT EXISTS (SELECT *
FROM YourTable AS b
WHERE b.Ticket = a.Ticket
AND b.date = a.date
AND b.department <> 2)
-- My second query
SELECT Ticket, date
FROM YourTable
GROUP BY Ticket, date
HAVING MIN(department) = 2
AND MAX(department) = 2
go
drop table YourTable
go
Check the output - both return only ticket 01, not ticket 02.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
.
- References:
- select query assistance
- From: AshleyT
- Re: select query assistance
- From: Hugo Kornelis
- Re: select query assistance
- From: AshleyT
- Re: select query assistance
- From: Hugo Kornelis
- Re: select query assistance
- From: AshleyT
- select query assistance
- Prev by Date: Re: select query assistance
- Next by Date: problem with sql
- Previous by thread: Re: select query assistance
- Next by thread: problem with sql
- Index(es):
Relevant Pages
|
|