相当新的SQL。我正在尝试计算有时在两个地区的假期查询中的预订 ID 总数。
这是我需要的..
ID count Region name
427139 1 France
427776 2 Spain
427776 2 France
但似乎只提供这个..
ID count Region name
427139 1 France
427776 1 Spain
427776 1 France
Bookings ID 是唯一的,但是当我从我的 Region 表中引入 Region 时(通过 Quotes 和 Properties 表),它被分成 2 行。
这是我的 SQL ..
SELECT count(BO.ID) as Count,
BO.ID AS 'Booking ID',
RE.Name AS 'Region name'
FROM Booking BO WITH (NOLOCK)
LEFT JOIN Quote QU WITH (NOLOCK) ON QU.ID = BO.QuoteID
LEFT JOIN Property PR WITH (NOLOCK) ON PR.Code = QU.Code
LEFT JOIN Region RE WITH (NOLOCK) ON RE.ID = PR.RegionID
WHERE BO.ID = '427776' OR BO.ID = '427139'
Group by BO.ID,RE.Name
ORDER BY BO.ID
任何人都可以帮忙吗?
感谢您的关注!