En måde er at bruge exists
prædikat med en korreleret underforespørgsel, der kontrollerer, at det specifikke symbol har mere end én pris.:
select * from table1 t
where exists (
select 1
from table1
where symbol = t.symbol
and price <> t.price);
Dette ville returnere:
| Date | Type | Symbol | Price |
|------------------------|------|-----------|--------|
| June, 30 1995 02:00:00 | gaus | 313586U72 | 109.25 |
| June, 30 1995 02:00:00 | gbus | 313586U72 | 108.94 |
| June, 30 1995 02:00:00 | agus | SRR | 10.25 |
| June, 30 1995 02:00:00 | lcus | SRR | 0.45 |
| July, 01 1995 02:00:00 | gaus | 313586U72 | 109.25 |
| July, 01 1995 02:00:00 | gbus | 313586U72 | 108.94 |
Edit:inspireret af Gordon Linoffs kloge svar en anden mulighed kunne være at bruge avg()
som en vinduesfunktion:
select Date, Type, Symbol, Price
from (
select Date, Type, Symbol, Price, avg = avg(price) over (partition by symbol)
from table1) a
where avg <> price;
Edit:med en kontrol for at sikre, at kun dubletter på samme dato returneres:http:/ /www.sqlfiddle.com/#!6/29d67/1