【问题标题】:How to use IF or Case statement in Select Query?如何在 Select Query 中使用 IF 或 Case 语句?
【发布时间】:2019-04-17 14:56:47
【问题描述】:

我正在尝试在某些情况下从数据库中获取数据,因为在代码级别它会在页面上产生巨大的负载。

我正在使用以下查询来执行此操作:

Select * From users If user_status='active' and user_group=2 on case 'student' and user_group=3 on case 'teacher'

如果你有mysql方面的经验,请帮我解决我的问题?

【问题讨论】:

  • 我想你需要wherestudent/teacher 是什么?
  • 你的目的是什么?

标签: php mysql wordpress if-statement case


【解决方案1】:
SELECT IF(user_status='active' and user_group=2, 'student', ''), IF(user_status='active' and user_group=3, 'teacher', '') FROM users

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 1970-01-01
    • 2012-09-04
    • 2018-12-06
    • 2023-01-06
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    相关资源
    最近更新 更多