select vs. select count

Поиск
Список
Период
Сортировка
От Claus Guttesen
Тема select vs. select count
Дата
Msg-id b41c75520703270537y12d83fe5w7fc58f6e35fbe13d@mail.gmail.com
обсуждение исходный текст
Ответы Re: select vs. select count  ("Claus Guttesen" <kometen@gmail.com>)
Re: select vs. select count  (Peter Eisentraut <peter_e@gmx.net>)
Re: select vs. select count  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Hi.

I'm performing the following query to get all items sold in 2006 which
are in category prints or gifts, but not in extra:

select order_id from(select o.order_id from orders o join order_lines ol using (order_id) where o.time >
'2006-01-01T00:00'and o.time < '2007-01-01T00:00' and (ol.item_id = 10 or ol.item_id = 11 or ol.item_id = 12) group by
 
o.order_id) as prints inner join(select ho.order_id from orders ho join order_lines hol using (order_id) where o.time >
'2006-01-01T00:00'and o.time < '2007-01-01T00:00' and (ol.item_id = 20 or ol.item_id = 21 or ol.item_id = 22) group by
 
o.order_id) as gifts using (order_id)except select order_id from (select ho.order_id from orders ho join order_lines
holusing (order_id)  where o.time > '2006-01-01T00:00' and o.time < '2007-01-01T00:00'  and (ol.item_id = 30 or
ol.item_id= 31 or ol.item_id = 32) group
 
by o.order_id) as extra;

When I do the 'select order_id' I get (after scrolling down):
order_id
---------
xyz
...
foo
bas
(1960 rows)

But when I do a 'select count(order_id) I get:
count
------- 2063

Why does select and select(count) produce two different results? Am I
doing something wrong here?

regards
Claus


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Sabin Coanda"
Дата:
Сообщение: array_to_string
Следующее
От: "Claus Guttesen"
Дата:
Сообщение: Re: select vs. select count