mysql case when使用
数据库表结构如下:
SQL语句:
select t.code1, sum(t.num) as num FROM (SELECT CASE WHEN code1 <= 2 THEN 2 WHEN code1 > 2 THEN 4 END code1, num FROM citys) t GROUP BY t.code1;
执行效果:
本文部分转自;https://www.cnblogs.com/linbo3168/p/12753260.html