Re: Query

Поиск
Список
Период
Сортировка
От ed.prochak@magicinterface.com (Ed prochak)
Тема Re: Query
Дата
Msg-id 4b5394b2.0406161014.2dbdf9f8@posting.google.com
обсуждение исходный текст
Ответ на Query  (dayzman@hotmail.com (Michael))
Список pgsql-general
dayzman@hotmail.com (Michael) wrote in message news:<48e30213.0406152231.6e19331c@posting.google.com>...
> Hi,
> If I have R(a integer PRIMARY KEY, b text, c text, d integer); and I
> want to find how many different entries there are, (specified using b
> and c instead of a), is "select count(distinct b||c) from R" an
> appropriate query?
(see note 1 below)
> ... Also, if I want to find how many of those that have
> a different "d", can I use "select count(d) from R goup by title ||
> author"?
(see note 2)
> ... What if b and c are integers, then I wouldn't be able to
> concatenate the 2 fields right?
(note 3, you see the patern by now)
>
> Please help.
>
> Thanks,
> Michael

Taking a summer school class?

(BTW, I personally hate the DISTINCT keyword, mainly because it is so
easily abused.)

Here are some things to think about:
Note 1: concatenating two text fields can bring incorrect results,
imagine these values for your query:
    b    c
   XY    Z
    X    YZ
your query, as written considers those two rows the same. Are they the
same? (depends on your application! your answer may be YES.)

Note 2: where did the "title" and "author" attributes come from?? IOW,
if you are making an example, be consistent within the example.

Note 3: Why would changing b and c to integers make a difference to
the LOGIC of the query? Isn't 123 a character string?


I'm not trying to hassle you. Just trying to help you Think it
through.

  Ed

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

Предыдущее
От: Antonin Guttman
Дата:
Сообщение: SNMP Agent
Следующее
От: "Laconic2"
Дата:
Сообщение: Re: Query