【发布时间】:2013-01-21 20:59:13
【问题描述】:
SELECT
rates_Calendar.date,
subQuery.name,
COALESCE(subQuery.amount,0) as amount,
subQuery.reference,
subQuery.property
FROM
rates_Calendar
LEFT JOIN (
SELECT
rates_Booking.date,
unit.unit,
unit.abbreviation as name,
rates_Booking.amount,
rates_Booking.bookingReference AS reference,
property.property
FROM
rates_Booking
LEFT JOIN booking ON booking.reference = rates_Booking.bookingReference
LEFT JOIN unit ON booking.apartment = unit.unit
LEFT JOIN property ON property.property = unit.property
# unit to apartments
LEFT JOIN apartments ON (apartments.unit = unit.unit)
LEFT JOIN apartmentTypes ON (apartmentTypes.id = apartments.apartmentTypeId)
WHERE
rates_Booking.date BETWEEN @startDate AND @endDate
AND unit.unit = 221
GROUP BY
property.area,
property.property,
apartmentTypes.id,
unit.unit,
rates_Booking.date
) AS subQuery ON subQuery.date = rates_Calendar.date
WHERE
rates_Calendar.date BETWEEN @startDate AND @endDate
GROUP BY
subQuery.reference,
subQuery.unit,
subQuery.apartmentTypeId,
subQuery.property,
subQuery.area,
rates_Calendar.date
现在,显然这个查询将导致不匹配的日期为 NULLS。 有没有办法用 NON NULL 值更新所有 NULLS?
2013-01-01 unitA 138 1 property1
2013-01-02 unitA 138 1 property1
2013-01-03 unitA 138 1 property1
2013-01-04 NULL 0 NULL NULL
2013-01-05 NULL 0 NULL NULL
有没有办法用相应列中的非空值更新空值?
我正在尝试这样做,因为从链接中可以理解,用 NULLS 隐藏 rowGroups 是不可能的: Hide NULL Row Groups JasperReports
【问题讨论】:
标签: mysql sql database group-by left-join