- 论坛徽章:
- 93
|
seesea2517 发表于 2016-05-26 10:44
回复 1# lvluo1988
有点顺序反了。如果是的话,如下方案可以参考:- mysql> select 68 - ascii('A'), 68 - ascii('B'), 68 - ascii('C');
- +-----------------+-----------------+-----------------+
- | 68 - ascii('A') | 68 - ascii('B') | 68 - ascii('C') |
- +-----------------+-----------------+-----------------+
- | 3 | 2 | 1 |
- +-----------------+-----------------+-----------------+
- 1 row in set
- mysql> set @score := 'A';
- select if(@score = 'A', 3, if(@score = 'B', 2, if('@score = C', 1, -1)));
- Query OK, 0 rows affected
- +-------------------------------------------------------------------+
- | if(@score = 'A', 3, if(@score = 'B', 2, if('@score = C', 1, -1))) |
- +-------------------------------------------------------------------+
- | 3 |
- +-------------------------------------------------------------------+
- 1 row in set
- mysql> set @score := 'A';
- select
- case @score
- when 'A' then 3
- when 'B' then 2
- when 'C' then 1
- else -1
- end;
- Query OK, 0 rows affected
- +---------------------------------------------------------------------+
- | case @score
- when 'A' then 3
- when 'B' then 2
- when 'C' then 1
- else -1
- end |
- +---------------------------------------------------------------------+
- | 3 |
- +---------------------------------------------------------------------+
- 1 row in set
- mysql>
复制代码 |
|