Insert into t values (' 2010-04-01 ', 'DAT501, 100);
Insert into t values (' 2010-04-01 ', 'DAT502, 120);
Insert into t values (' 2010-04-01 ', 'DAT503, 130);
Insert into t values (' 2010-04-02 ', 'DAT501, 110);
Insert into t values (' 2010-04-02 ', 'DAT502, 105);
Insert into t values (' 2010-04-03 ', 'DAT503, 125);
Insert into t values (' 2010-04-04 ', 'DAT501, 100);
Insert into t values (' 2010-04-04 ', 'DAT503, 200);
- to get the following resultsDay | dat501 | dat502 | dat503
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- --
The 2010-04-01 | 100 | 120 | 130
The 2010-04-02 | | 110 | 105
The 2010-04-03 | | | 125
The 100 | 2010-04-04 | | 200
CodePudding user response:
This should only be handled through the way of relating:The select t.d ay, t1 equipment DAT501, t2. The equipment DAT502, t3. Equipment DAT503
The from (select distinct day from t) t
Left the join t t1
On t.d ay=t1. Day
And t1. Equipment='DAT501'
Left the join t t2
On t.d ay=t2. Day
And t2. Equipment='DAT502'
Left the join t t3
On t.d ay=t3. Day
And t3. Equipment='DAT503'
The order by t1. Day
CodePudding user response:
http://blog.csdn.net/zeeeitch/article/details/6086257CodePudding user response:
http://blog.csdn.net/post_yuan/article/details/52464004