sqlserver的case when 语句如何转 mysql
如以下sqlserver
select ifnull(case when adid>1 then adid end),0) from advertisement不知道是否mysql有对应sql
如以下sqlserver
select ifnull(case when adid>1 then adid end),0) from advertisement不知道是否mysql有对应sql
俺发现mysql好像无法支持在遍历过程中对变量赋值,举个例子说:
select
@x=case when column1<10 then 10 else column1 end
from
table1
但这样的语句在sqlserver中就能运行
请大家谈谈想法
insert into tab1 values(1,1);
insert into tab1 values(10,10);
insert into tab1 values(100,100);
insert into tab1 values(null,0);mysql> select ifnull(case when col1>1 then col1 end, 0), col2 from tab1;
+-------------------------------------------+------+
| ifnull(case when col1>1 then col1 end, 0) | col2 |
+-------------------------------------------+------+
| 0 | 1 |
| 10 | 10 |
| 100 | 100 |
| 0 | 0 |
+-------------------------------------------+------+
4 rows in set (0.00 sec)
+------+------+------+
| x | col1 | col2 |
+------+------+------+
| 10 | 1 | 1 |
| 10 | 10 | 10 |
| 100 | 100 | 100 |
| NULL | NULL | 0 |
+------+------+------+
4 rows in set (0.00 sec)
不过还是谢谢wenzhulz(触丝)的想法。:)