相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- sqlyog export query result as csv
SELECT student,
SUM(CASE course WHEN '语文'THEN score END)AS '语文',
SUM(CASE course WHEN '数学'THEN score END)AS '数学',
SUM(CASE course WHEN '英语'THEN score END)AS '英语'
FROM Score GROUP BY student
SELECT * FROM aaa /*数据源*/
P
PIVOT
(
SUM(id) FOR
p.bb/*需要行转列的列*/ IN ('语文','数学','英语','生物'/*列的值*/)
) AS T
不会.百度:sql行转列.
面试问sql行转列怎么写.我都回:不写sql
select student as name,(select b.score from score b where a.student=b.student and b.course='语文') as '语文'
,(select b.score from score b where a.student=b.student and b.course='数学') as '数学'
,(select b.score from score b where a.student=b.student and b.course='英语') as '英语' from score a group by student