让我们首先创建一个表-
mysql> create table DemoTable ( PageId int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(233); mysql> insert into DemoTable values(34); mysql> insert into DemoTable values(76); mysql> insert into DemoTable values(89);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+ | PageId | +--------+ | 233 | | 34 | | 76 | | 89 | +--------+ 4 rows in set (0.00 sec)
以下是带有SELECT的CASE WHEN的查询-
mysql> select PageId, case when PageId %2 !=0 then 'PageId is odd' else 'PageId is even' end AS Result from DemoTable;
这将产生以下输出-
+--------+----------------+ | PageId | Result | +--------+----------------+ | 233 | PageId is odd | | 34 | PageId is even| | 76 | PageId is even| | 89 | PageId is odd| +--------+----------------+ 4 rows in set (0.00 sec)