sql语句 两值对比返回true 或者false 关于程序的题目

解法一: 

create table DemoTable
(
   FirstName varchar(100),
   LastName varchar(100)
);

 insert into DemoTable values('Chris','Brown');
 insert into DemoTable values('David','Miller');
 insert into DemoTable values('Adam','Smith');

 查询判断返回相关内容

select if(LastName='Miller','Yes','No') AS LastName,FirstName from DemoTable;

 解法二: 

case when

CASE [col_name] WHEN [value1] THEN [result1]…ELSE [default] END
CASE WHEN [expr] THEN [result1]…ELSE [default] END

SELECT
    NAME '英雄',
    CASE NAME
        WHEN '德莱文' THEN
            '斧子'
        WHEN '德玛西亚-盖伦' THEN
            '大宝剑'
        WHEN '暗夜猎手-VN' THEN
            '弩'
        ELSE
            '无'
    END '装备'
FROM
    user_info;

你可能感兴趣的:(MySQL,mybatis,java,sql)