Re: Crosstab function

Поиск
Список
Период
Сортировка
От David G Johnston
Тема Re: Crosstab function
Дата
Msg-id 1399299903660-5802456.post@n5.nabble.com
обсуждение исходный текст
Ответ на Crosstab function  ("Hengky Liwandouw" <hengkyliwandouw@gmail.com>)
Ответы Re: Crosstab function
Список pgsql-general
Hengky Lie wrote
> The crosstab warehouse column name (OFFICE & Store2) is taken from
> tblwarehouse so when user add warehouse, crosstab column name will change
> automatically. And also each row has total qty.

In what programming language?  The only way to do this is to dynamically
construct the appropriate query, with the correct number of columns,
on-the-fly in the client application and send it as a normal query to the
server.  There is no pure SQL solution.

For the total column you will need a virtual warehouse that holds those
values.  Likely the easiest way to get that will be to UNION ALL the main
real warehouse query and another query the groups by product and sum-counts
that values from the individual warehouses.

IIRC you've already been shown how to write the basic crosstab query; this
really isn't any different but you will need procedural logic and some way
to dynamically build a SQL query string based upon how many warehouses you
have at the time you run the query.

I am assuming you know how to write the basic join query to get the general
form needed for the real warehouse data.

David J.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Crosstab-function-tp5802402p5802456.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: Monitoring Pg servers with Microsoft SCOM
Следующее
От: Tim Clarke
Дата:
Сообщение: envelope/postage announcement