1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| SELECT apsoc.id_society
, askpart.id_article
, soc.tl_name
, apsoc.bo_choice
, apsoc.bo_choice_by_vendor
FROM tbl_ask_price_society AS apsoc
INNER JOIN
tbl_society AS soc
ON soc.id_society = apsoc.id_society
INNER JOIN
tbl_ask_price_article AS askpart
ON askpart.id_ask_price_article = apsoc.id_ask_price_article
INNER JOIN
tbl_articles_price_buy AS artpriceb
ON artpriceb.id_article = askpart.id_article
INNER JOIN
tbl_articles_price_sell AS artprice
ON artprice.id_article = askpart.id_article
WHERE askpart.id_askprice = apsoc.idaskprice
AND EXISTS
( SELECT 1
FROM tbl_articles_price_buy as artpb
WHERE artpb.id_article = askpart.id_article
HAVING artpriceb.dt_price = MAX(artpb.dt_price)
)
AND EXISTS
( SELECT 1
FROM tbl_articles_price_sell AS artp2
WHERE artp2.id_article = askpart.id_article
HAVING artprice.dt_price = MAX(artp2.dt_price)
)
-- WHERE askpart.id_askprice = apsoc.idaskprice |
Partager