1 2 has
1 3
2 1
3 2
1 2 has
To:
Teachers,
on Monday, Tuesday, Wednesday1 2 1
2 1
3 1
Through SQL record of the above to the following shows how to get, for a great god
CodePudding user response:
The building Lord baidu "line turned column", there are questions to ask;CodePudding user response:
1, go to the heavy, can consider to create a function over (partition by... );2, considering the transfer line column, column turned, there are the pivot in Oracle and unpivot;
3, it is better to stick a formatting code and screenshots, ready to give you build a list of derivative according to try, but did not understand the specific requirements, first to work, have a question to ask,
CodePudding user response:
1, first to heavy, can consider to open the window function over (partition by... );2, turn to consider line column, column turned, there are the pivot in Oracle and unpivot;
3, it is better to stick a formatting code and screenshots, ready to give you build a list of derivative according to try, but did not understand the specific requirements, first to work, have a question to ask,
[a post in haste above have wrong character]
CodePudding user response:
- the building data description not clear can only guess at the followingSQL> With t (" teachers ", b, c) as (
2 the select '1', '2', 'a' from dual
3 union all
4 the select '1', '3', 'a' from dual
5 union all
Select 6 '2', '1', 'a' from dual
7 union all
8 the select '3', '2', 'a' from dual
9 union all
10 the select '1', '2', 'a' from dual)
11 the SELECT * FROM (
12 the SELECT "teachers", the FROM T b WHERE c='a')
13 the PIVOT (COUNT (*) FOR b IN (' 1 'AS "Monday",' 2 'AS "Tuesday",' 3 'AS "Wednesday"))
14 the ORDER BY 1
15/
Teachers,
on Monday, Tuesday, Wednesday-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1 0 2 1
2 1 0 0
3 1 0 0