Skip to content

Instantly share code, notes, and snippets.

@abmathewks
Created March 20, 2022 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abmathewks/bb0e753dbde4a6e9dc8e2dae35de83b3 to your computer and use it in GitHub Desktop.
Save abmathewks/bb0e753dbde4a6e9dc8e2dae35de83b3 to your computer and use it in GitHub Desktop.
SELECT
ob.lead_id,
DATE(ob.create_date),
TIME(ob.create_date),
ob.affiliate_id,
ob.amount AS 'our_cost',
ob.won_ping,
ob.lead_type
FROM our_bids AS ob
INNER JOIN leads AS l ON ob.lead_id = l.id
WHERE ob.affiliate_id = 1008
AND lead_type = 'AUTO'
AND ob.id >=
(SELECT
id
FROM
(
SELECT id FROM our_bids
WHERE affiliate_id = 1008 AND lead_type = 'AUTO' AND won_ping = 1
ORDER BY id DESC
LIMIT 50
) tb1
ORDER BY id ASC
LIMIT 1)
ORDER BY won_ping DESC, our_cost DESC
LIMIT 5000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment