Skip to content

Instantly share code, notes, and snippets.

@airburst
Created June 29, 2023 15:39
Show Gist options
  • Save airburst/f2db7bde71e4f5290a6065c81ffc75ea to your computer and use it in GitHub Desktop.
Save airburst/f2db7bde71e4f5290a6065c81ffc75ea to your computer and use it in GitHub Desktop.
-- Get all of today's rides that have no riders
SELECT r.id from Ride r
LEFT OUTER JOIN (
SELECT rideId, CAST(count(*) as UNSIGNED) cnt
FROM UsersOnRides
GROUP BY rideId
) ur ON ur.rideId = r.id
where DATE_FORMAT(r.date,'%d/%m/%Y') = DATE_FORMAT(NOW(),'%d/%m/%Y')
and COALESCE(ur.cnt,0) = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment