我用的的是mysql 数据库

       前不久,又要业务需要,要写出if else 样式结果集,的sql,在次之前,对case when then end不太熟悉

查阅后sql 文档后,学会了case when then end 的用法

1.

       case '字段' when (字段= 值1) then 结果

                           when (字段=值2) then 结果

                            else 结果

                            end

    eg.

      select a.id,a.status,a,age from a

            (case status when status='1' then "在会"

                                when status='0' then "未知"

                               when statsu='-1' then '离开'

            end) =1

   这个sql 可将 status为1 的 记录查询出来

2.另外 case when (表达式1)then 结果

                   when (表达式1) then 结果

                   else 结果

                   end

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-01-27
  • 2021-09-20
猜你喜欢
  • 2021-10-20
  • 2021-12-02
  • 2022-12-23
  • 2021-08-19
  • 2021-08-04
  • 2021-07-06
  • 2022-12-23
相关资源
相似解决方案