【问题标题】:MYSQL hide field data if value in another field is set如果设置了另一个字段中的值,则 MYSQL 隐藏字段数据
【发布时间】:2013-09-10 15:07:19
【问题描述】:

有一张这样的桌子:

art.    type    price
a        b       1
a        c       2

是否可以通过选择将过滤后的内容显示为:

art.    type    price
a        b       
a        c       2

如果类型为“b”,则不显示价格数据?

select art, type, price from x 
where type="b" hide price

【问题讨论】:

  • 决定一个字段是否应该隐藏的条件是什么?

标签: mysql select if-statement where data-representation


【解决方案1】:

这种逻辑可能最好属于应用程序的表示层,而不是数据库层。然而,仍然可以使用 MySQL 的 IF() 函数或其 CASE 表达式——例如:

SELECT art, type, IF(type='b',NULL,price) price FROM x;

sqlfiddle 上查看。

【讨论】:

    猜你喜欢
    • 2014-04-08
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多