想要获取的列。

    1. select * from info;
    2. select id, name from info;
    3. select id, name as NM from info;
    4. select id, name as NM, 123 from info;
    5. select id, name as NM, 123 as age from info;
    1. select
    2. id,
    3. name,
    4. 666 as num,
    5. ( select max(id) from depart ) as mid, -- max/min/sum
    6. ( select min(id) from depart) as nid, -- max/min/sum
    7. age
    8. from info;
    9. # 注意:效率很低
    1. select
    2. id,
    3. name,
    4. case depart_id when 1 then "第1部门" end v1
    5. from info;
    6. select
    7. id,
    8. name,
    9. case depart_id when 1 then "第1部门" else "其他" end v2
    10. from info;
    11. select
    12. id,
    13. name,
    14. case depart_id when 1 then "第1部门" end v1,
    15. case depart_id when 1 then "第1部门" else "其他" end v2,
    16. case depart_id when 1 then "第1部门" when 2 then "第2部门" else "其他" end v3,
    17. case when age<18 then "少年" end v4,
    18. case when age<18 then "少年" else "油腻男" end v5,
    19. case when age<18 then "少年" when age<30 then "青年" else "油腻男" end v6
    20. from info;