
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;
