Re: [SQL] Tricky -to me!- SQL query.
От | Remigiusz Sokolowski |
---|---|
Тема | Re: [SQL] Tricky -to me!- SQL query. |
Дата | |
Msg-id | Pine.GS4.4.02A.9901121239190.7827-100000@netra.gdansk.sprint.pl обсуждение исходный текст |
Ответ на | [SQL] Tricky -to me!- SQL query. (stuart@ludwig.ucl.ac.uk (Stuart Rison)) |
Список | pgsql-sql |
> > Consider the following table: > dev_brecard=> select * from test order by person; > person|fruit > ------+--------- > lucy |mandarins > lucy |tomatoes > lucy |pears > lucy |oranges > lucy |apples > peter |pears > peter |apples > peter |oranges > peter |prunes > robert|figs > robert|dates > stuart|apples > stuart|pears > stuart|prunes > stuart|bananas > stuart|kumquats > (16 rows) > > (code for creating and populating table is in a PS at the end of this posting) > > You can assume that the table is appropriately normalised and that there is > a composite primary key for it (i.e. each COMBINATION of person and fruit > will appear only once and neither of the fields can be NULL) > > How do I select from all person who like 'pears' and 'apples' (in this > case, lucy, peter and stuart) or 'pears', 'apples' and 'oranges' (in this > case, lucy and peter)? What about: SELECT person FROM test WHERE fruit='pears' AND fruit='apples' AND fruit='oranges'; or just SELECT person FROM test WHERE fruit IN ('pears', 'apples','oranges'); For me strange question - so I think I don't mean exactly what you do ;-) Could You explain for what You wanna this? Rem -------------------------------------------------------------------*------------ Remigiusz Sokolowski e-mail: rems@gdansk.sprint.pl * * -----------------------------------------------------------------*****----------
В списке pgsql-sql по дате отправления: