2012年11月30日 星期五

sql 橫向顯示


  1. SELECT id_num, MAX(score_chinese) AS '國文成績', MAX(score_english) AS '英文成績', MAX(score_math) AS '數學成績'
  2. FROM(
  3. SELECT id_num,
  4. CASE WHEN subject='國文' THEN score END AS score_chinese,
  5. CASE WHEN subject='英文' THEN score END AS score_english,
  6. CASE WHEN subject='數學' THEN scree END AS score_math
  7. FROM score_table
  8. ) AS score_table_tmp
  9. GROUP BY id_num

沒有留言:

張貼留言