Updating with a subselect

Поиск
Список
Период
Сортировка
От Leandro Casadei
Тема Updating with a subselect
Дата
Msg-id 5983afbb0804220917x3771415boc6299d0ba6d9f328@mail.gmail.com
обсуждение исходный текст
Ответы Re: Updating with a subselect  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Re: Updating with a subselect  (Martijn van Oosterhout <kleptog@svana.org>)
Re: Updating with a subselect  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список pgsql-general
Hi, I need to update a field from a table based in a count.

This is the query:


update    shops
set    itemsqty =
    (
    select     count(*)
    from     items i1
    join      shops s1 on i1.shopid = s1.shopid
    where   s1.shopid = s0.shopid
    )
from     shops s0


The problem I'm having is that all the shops are updated with the items quantity of the first shop.
I've tried using the count without a subselect, but PostgreSQL complains about it.

How can I do this?

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

Предыдущее
От: "Vanole, Mike"
Дата:
Сообщение: Best approach for large table maintenance
Следующее
От: mateo21@siteduzero.com
Дата:
Сообщение: Bitmap Heap Scan takes a lot of time