雲端計算學習路線圖素材、課件,CASE的其他用法講解

千鋒雲端計算發表於2019-12-24

在本篇文章中將給大家講解下CASE的其他用法講解:

雲端計算學習路線圖素材、課件,CASE的其他用法講解

使用帶有簡單CASE函式和CASE搜尋函式的select語句在select語句中,CASE搜尋函式允許根據比較值

select

CASE

WHEN good_type<2

THEN '<2'

WHEN good_type>=2 AND good_type<3

THEN '>=2 && <3'

ELSE '>=3' END AS good_now_type,

good_type,user_id,user_name

FROM t_main_order;

+---------------+-----------+---------+-----------+

| good_now_type | good_type | user_id | user_name |

+---------------+-----------+---------+-----------+

| <2 | 0 | 1 | tina |

| <2 | 0 | 2 | tige |

| <2 | 1 | 3 | five |

| >=2 && <3 | 2 | 4 | wate |

| >=3 | 3 | 5 | fiww |

| >=3 | 3 | 6 | www |

| >=3 | 3 | 7 | wfiw |

+---------------+-----------+---------+-----------+

CASE的其他用法

select

CASE

WHEN good_type<2

THEN '<2'

WHEN good_type>=2 AND good_type<3

THEN '>=2 && <3' ELSE '>=3'

END AS good_now_type,

count(*) AS num_count

FROM t_main_order

GROUP BY good_now_type

ORDER BY num_count;

+---------------+-----------+

| good_now_type | num_count |

+---------------+-----------+

| >=2 && <3 | 1 |

| <2 | 3 |

| >=3 | 3 |

+---------------+-----------+


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69916964/viewspace-2670097/,如需轉載,請註明出處,否則將追究法律責任。

相關文章