我有一個交叉表SQL,我沒有得到預期的結果作爲輸出。我得到了第一列的所有值。這裏是我的SQL:如何使用交叉表以正確的列獲取值?
select * from crosstab
('select p.name::text as product,
pc.name as prod_cat,
sum(ms.qtyonhand) as total_stock from adempiere.m_product p
join adempiere.m_product_category pc on p.m_product_category_id=pc.m_product_category_id
join adempiere.m_storage ms on ms.m_product_id=p.m_product_id
group by prod_cat,product order by 3 desc') as ct
(product text,
"ELECTRICAL & ELECTRONIC ITEMS" numeric,
"ACADEMICS BOOKS" numeric,
"Standard" numeric,
"FOOD AND BEVERAGES" numeric,
"Possibly Product Category" numeric,
"Pharmacy Medicine" numeric,
"COMPUTER & ACCESSORIES" numeric)
limit 10
,這是我得到的輸出:http://i.stack.imgur.com/w6gc5.png
這就是我要找的輸出:
product | Electricals | Electronics | Food & Beverages | Cosmetics | Hardwares
---------------------|-------------|---------------|-------------------|------------|-------------
Samsung-WM | | 4552 | | |
Videocon-Refridge | | 1254 | | |
Philips-CFL Bulbs | 5677 | | | |
Head&shoulder Shampoo| | | | 4567 |
Candysweet | | | 5678 | |
Icecreams | | | 6785 | |
Paints | | | | | 9876
Taps | | | | | 10987
Electrical wires | 18796 | | | |
如何修改我的查詢來獲取適當的結果?
不發佈圖片發佈數據。你期望的輸出是什麼? – e4c5