SQL-列相乘时不返回值
我的数据库表中有 3 列,我需要将列、itm_count 和 itm_count 相乘。 itm_price 并输出给定 id(itm_id) 的总计。
SELECT sum(itm_price * itm_count) as total FROM ods_temporder WHERE itm_id='11'
我尝试使用上面的 sql 查询来执行此操作,但结果为空。这里似乎有什么问题?
I have 3 columns in my db table, I need to multiply column, itm_count & itm_price and output the total for a given id(itm_id).
SELECT sum(itm_price * itm_count) as total FROM ods_temporder WHERE itm_id='11'
I tried to do this using the above sql query, but the result was null. What seems to be the issue here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这给你带来什么?
itm_price
或itm_count
是否为 NULL?您有itm_id
= 11 的行吗?What do this give you?
Is either of
itm_price
oritm_count
NULL? Do you have rows foritm_id
= 11?尝试:
COALESCE 是处理 NULL 值的 ANSI 标准 - 如果
itm_price
或itm_count
为 null,则在这种情况下将使用零作为值。否则,要么itm_id
列中没有值为 11 的行,要么您在错误的列中查找 11 值。Try:
COALESCE is an ANSI standard for dealing with NULL values - if
itm_price
oritm_count
is null, zero will be used in this case as the value. Otherwise, either you don't have a row with a value of 11 for theitm_id
column, or you're looking for the 11 value in the wrong column.当itm_id=11时itm_price和itm_count包含什么?
这是 SQL Server 吗?如果是这样,您可以使用 ISNULL 来处理 itm_price 或 itm_count 是否为 null
What does itm_price and itm_count contain when itm_id= 11?
Is this SQL Server? If so you can use ISNULL to handle whether itm_price or itm_count is null