sql用null或文本替换零0值
我有一张产品表
某些 ProductPrice 值为 0(类型为十进制(10,0))
ID | Productname | ProductPrice |
+----+-------------+--------------------------------------+
| 1 | ShirtXS | 299 |
| 2 | TrousersM | 0 |
ProductPrice 为 DECIMAL(10,0)。
如何编写 SQL 查询来将 ProductPrice 值 0 转换/替换为 NULL 或文本 N/A?
期望的输出:
ID | Productname | ProductPrice |
+----+-------------+--------------------------------------+
| 1 | ShirtXS | 299 |
| 2 | TrousersM | NULL or N/A |
I have a table Products
Some ProductPrice values are 0 (type is decimal(10,0))
ID | Productname | ProductPrice |
+----+-------------+--------------------------------------+
| 1 | ShirtXS | 299 |
| 2 | TrousersM | 0 |
ProductPrice is DECIMAL(10,0).
How to write SQL query to convert/replace ProductPrice value 0 with NULL or text N/A?
Desired output:
ID | Productname | ProductPrice |
+----+-------------+--------------------------------------+
| 1 | ShirtXS | 299 |
| 2 | TrousersM | NULL or N/A |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否正在寻找
更新
或选择
。如果您正在寻找选择
可以从mysql使用nullif()
以替换0
用null
。语法如下:I'm not sure if you are looking to
UPDATE
orSELECT
. If you are looking forSELECT
you can useNULLIF()
from MySQL to replace0
withNULL
. The syntax is below:为此使用
case
表达式:Use
case
expression for this: