SQL复杂查询最大组最大记录优化记录

 

SELECT w.*,p.id,p.price FROM wareprice_01 p,(SELECT a.wareid,a.platform,`value` attr,attrid,title,url,shopid FROM wareattr_01 a,ware_01 w

    WHERE a.wareid = w.wareid AND a.platform=w.platform AND (`value` LIKE ‘%月光石%’ OR title LIKE ‘%月光石%’) GROUP BY a.wareid) w

    WHERE w.wareid=p.wareid AND w.platform=p.platform AND p.id=(SELECT MAX(id) FROM wareprice_01 t WHERE p.wareid=t.wareid);

 

SELECT nw.*,np.id,np.price FROM (SELECT price,platform,id,wareid FROM wareprice_01 p1 WHERE id=(SELECT MAX(id) FROM wareprice_01 p2 WHERE p1.wareid=p2.wareid)) np,(SELECT a.wareid,a.platform,`value` attr,attrid,title,url,shopid FROM wareattr_01 a,ware_01 w

    WHERE a.wareid = w.wareid AND a.platform=w.platform AND (`value` LIKE ‘%月光石%’ OR title LIKE ‘%月光石%’) GROUP BY a.wareid) nw WHERE np.wareid=nw.wareid AND np.platform=nw.platform;

 

SELECT s.*,wp.* FROM shop s,(SELECT nw.*,p.id,p.price FROM wareprice_01 p,(SELECT a.wareid,a.platform,`value` attr,attrid,title,url,shopid FROM wareattr_01 a,ware_01 w WHERE a.wareid = w.wareid AND a.platform=w.platform AND (a.`value` LIKE ‘%月光石%’ OR title LIKE ‘%月光石%’) GROUP BY a.wareid) nw  WHERE nw.wareid=p.wareid AND nw.platform=p.platform AND p.id=(SELECT MAX(id) FROM wareprice_01 p2 WHERE p.wareid=p2.wareid)) wp WHERE s.id = wp.shopid;

 

SELECT * FROM wareprice_01 w1 WHERE id=(SELECT MAX(id) FROM wareprice_01 w2 WHERE w1.wareid=w2.wareid);

SELECT * FROM wareprice_01 w1 WHERE id IN (SELECT MAX(id) FROM wareprice_01 w2 WHERE w1.wareid=w2.wareid) LIMIT 5000;

SELECT * FROM wareprice_01 w1 GROUP BY wareid LIMIT 5000;消耗比较高