0
如何在PostgreSQL中使用交叉表函數,我嘗試了自己的查詢但仍無法正常工作。我有以下表格:如何在PostgreSQL中創建交叉表查詢
sampling_point time_sampling entero sampling_type
wall 06:53 50 Environment
floor 09:21 50 Environment
wall 09:22 50 Environment
wall 09:23 50 Environment
floor 06:52 10 Environment
wall 06:53 50 Environment
floor 06:32 10 Environment
wall 06:33 50 Environment
floor 06:32 50 Environment
wall 06:33 50 Environment
floor 06:52 50 Environment
floor 09:22 50 Environment
,我想創建查詢返回以下交叉:
sampling_point time_sampling entero_floor entero_wall
wall 06:53 50
wall 09:22 50
wall 09:23 50
wall 06:53 50
wall 06:33 50
wall 06:33 50
floor 09:21 50
floor 06:52 10
floor 06:32 10
floor 06:32 50
floor 06:52 50
floor 09:22 50
我使用交叉()有兩個參數是這樣的:
SELECT * FROM crosstab
(
'SELECT c.sampling_date, c.sampling_point, c.time_sampling, c.ha_entero
FROM (select t066dtl.*, t066hdr.* from tblfrmintqad066dtl t066dtl
JOIN tblfrmintqad066hdr t066hdr ON t066hdr.headerid = t066dtl.headerid AND t066dtl.status= 1) c
ORDER BY 1,2',
$$VALUES ('floor'::text),('wall'::text)$$
)
AS ct (sampling_point varchar, floor varchar, wall varchar) c.sampling_date = '2016-05-12';
在此先感謝。
這只是一個簡單的條件'CASE WHEN'。 – Parfait
所以我不必使用交叉表?你可以舉一些例子如何使用'CASE WHEN' – metaphor