I have the following 3 tables:
airport
airport_id name
1 Frankfurt
2 Paris
3 Amsterdam
area
areaid name airport_id
1 name1 2
2 name2 2
3 name3 3
4 name4 3
booking
id booking_date price commission areaid
1 2022-09-1T10:00 70 12 1
2 2022-09-2T11:00 60 16 2
3 2022-09-2T20:00 50 15 3
4 2022-09-3T01:00 110 15 3
5 2022-09-10T22:00 90 14 4
6 2022-09-11T19:00 65 12 1
7 2022-09-20T12:00 84 16 2
And I have this query
SELECT ar.name,
(SELECT (b.price * b.commission) AS com
FROM booking AS b
LEFT JOIN area AS p ON b.areaid = p.areaid
AND p.areaid = 3
AND (b.booking_date >= '2022-09-01T00:00' AND b.booking_date <= '2022-09-30T23:59:59')
)
FROM airport AS ar WHERE ar.airport_id = 2
Running the query I get the error:
more than one row returned by a subquery used as an expression
I don't understand what the problem is.
I added an SQL Fiddle to play with: http://sqlfiddle.com/#!17/8a09f/1