替换 LEFT OUTER JOIN 中返回的空值
SELECT WO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, WO_BreakerRail.Rejected, WO_BreakerRail.RejectedToCrop, WO_BreakerRail.Date
FROM indRailType LEFT OUTER JOIN
WO_BreakerRail ON indRailType.RailCode = WO_BreakerRail.RailCode AND WO_BreakerRail.Date = @date
返回时,日期列中存在 NULL 值,其中 WO_BreakerRail 中没有匹配的行。有没有办法用 @date 替换那些 NULL 值?
SELECT WO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, WO_BreakerRail.Rejected, WO_BreakerRail.RejectedToCrop, WO_BreakerRail.Date
FROM indRailType LEFT OUTER JOIN
WO_BreakerRail ON indRailType.RailCode = WO_BreakerRail.RailCode AND WO_BreakerRail.Date = @date
When this returns, there are NULL values in the Date column where there are no matching rows from WO_BreakerRail. Is there a way to replace just those NULL values with @date?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 oracle 和 sql server 中,您可以使用 COALESCE (oracle版本)函数
In oracle and sql server, you can use the COALESCE (oracle version) function
您可以使用
COALESCE
函数(转到 这里 获取 mysql 文档)或者您可以使用简单的 IF:
You can use
COALESCE
function (go here for mysql documentation)or you can use a simple IF:
是的,只需使用
COALESCE
,例如。COALESCE(WO_BreakerRail.Date, @date)
Yes, just use
COALESCE
, eg.COALESCE(WO_BreakerRail.Date, @date)
实际上,MySQL中有一个IFNULL()函数。
Actually, in MySQL there is a IFNULL() function.