如果设置了另一个字段中的值,则MYSQL隐藏字段数据 [英] MYSQL hide field data if value in another field is set

查看:341
本文介绍了如果设置了另一个字段中的值,则MYSQL隐藏字段数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

得到如下表:

art.    type    price
a        b       1
a        c       2

可以选择显示过滤内容为:

would it be possible with a select to show filtered content as:

art.    type    price
a        b       
a        c       2

如果类型为b则不要不显示价格数据?

so that if the type is "b" don't show price data?

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


推荐答案

此类逻辑可能最适合演示文稿,而不是数据库,您的应用程序层。但是,可以使用MySQL的 IF() 函数或其 CASE 表达式—例如:

Logic of this sort probably best belongs in the presentation, rather than database, layer of your application. However, it is nevertheless possible using either MySQL's IF() function or its CASE expression—for example:

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

sqlfiddle

这篇关于如果设置了另一个字段中的值,则MYSQL隐藏字段数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆