开发者

Replace returned null values in LEFT OUTER JOIN

开发者 https://www.devze.com 2022-12-24 04:07 出处:网络
SELECTWO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, WO_BreakerRail.Rejected, WO_BreakerRail.Rejecte
SELECT        WO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, WO_BreakerRail.Rejected, WO_BreakerRail.RejectedToCr开发者_运维问答op, 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?


In oracle and sql server, you can use the COALESCE (oracle version) function

SELECT ...., COALESCE(WO_BreakerRail.Date, @date)


You can use COALESCE function (go here for mysql documentation)

COALESCE(WO_BreakerRail.Date, @date)

or you can use a simple IF:

IF(WO_BreakerRail.Date IS NULL, @date, WO_BreakerRail.Date)


Yes, just use COALESCE, eg. COALESCE(WO_BreakerRail.Date, @date)


Actually, in MySQL there is a IFNULL() function.

select
  ifnull(wo_breakerrail.date, @date) as `date`,
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号