DECODE
语法:
SELECT DECODE( <EXPR,SEARCH1,RESULT1,SEARCH2,RESULT2,...[,DEFAULT]>) FROM <TABLE_NAME>
e.g.:
select orderno,decode(ostatus,'p','准备处理','c','已完成')
from order_master
此函数可用于行转列:
select * from score
SELECT u_id, stu_name, SUM (DECODE (score_type, '语文', score, 0)) AS 语文, /*or use max()*/ SUM (DECODE (score_type, '数学', score, 0)) AS 数学, SUM (DECODE (score_type, '外语', score, 0)) AS 外语 FROM score --where u_id>1 GROUP BY u_id, stu_name --having u_id >1 ORDER BY u_id