SELECT COUNT(pit.id) AS count, MAX(p.name) AS name
FROM Passenger AS p
LEFT JOIN Pass_in_trip AS pit ON p.id = pit.passenger
GROUP BY p.id
SELECT (SELECT COUNT(pit.id) FROM Pass_in_trip AS pit WHERE p.id = pit.passenger) AS count, p.name
FROM Passenger AS p
SUM(IF(v.direct = 'UP', 1, -1)) AS post_rate
SUM(CASE WHEN v.direct = 'UP' THEN 1 ELSE -1 END) AS post_rate
Если вариантов может быть больше, выражение более громоздкое:SUM(CASE WHEN v.direct = 'UP' THEN 1 WHEN v.direct = 'DOWN' THEN -1 ELSE 0 END) AS post_rate
SELECT
order_id,
MAX(order_sum) AS d_sum
FROM table
GROUP BY order_id
HAVING COUNT(id) > 1
SELECT SUM(d_sum) AS a_sum
FROM (
SELECT
order_id,
MAX(order_sum) AS d_sum
FROM table
GROUP BY order_id
HAVING COUNT(id) > 1
) AS q
SELECT a.* FROM Apartment a
LEFT JOIN Apartment_Dates ad
ON ad.apartment_id=a.id AND ? BETWEEN ad.arrival_time AND ad.departure_time
WHERE ad.id IS NULL