SELECT
bookingReference,
SUM(amount)
FROM
rates_Booking
WHERE date BETWEEN '2016-09-01' AND '2016-09-30'
GROUP BY bookingReference;
SELECT booking_type.`name` as booking_type
FROM booking_type
LEFT JOIN booking ON booking_type.`name`=booking.booking_type;
我想连接两个表。我想要这样的结果:
column1 column2 column3
----------
bookingReference sum(amount) booking_type
----------
0993979-00 £500 booking
----------
我假设在第一个和第二个数据集之间有一些连接列。在本例中,我所做的只是在预订参考列(假设该列在两个数据集中)上连接两者。根据给定的信息量很难判断。但如果有引用列那就只能是一个简单的内连接
SELECT
A.bookingReference,SUM(A.amount), booking_type.`name` as booking_type
FROM
rates_Booking A
inner join booking_type B ON A.bookingReference = B.bookingReference
left join booking ON booking_type.`name`=booking.booking_type
WHERE date BETWEEN '2016-09-01' AND '2016-09-30'
GROUP BY A.bookingReference,booking_type.`name`;