请原谅我的英语,但没有人可以用法语回答;-)
我正在做这个请求:
SELECT AVG(tyd.price) AS avg_price, COUNT(tyd.id_product) AS cnt_id_p,
catalog.id_marchand, catalog.id_product, catalog.price AS c_price,
catalog.img_src, tyd.login AS tyd_l
FROM catalog
INNER JOIN tyd ON catalog.id_marchand = tyd.id_marchand
AND catalog.id_product = tyd.id_product
WHERE tyd.login = "[email protected]"
AND tyd.step = "0"
GROUP BY catalog.id_product, catalog.id_marchand
但是当然 AVG & COUNT 函数不起作用,因为我的条件只有一行。
我想要做的仍然是获得我独特的线路,但让 AVG 和 COUNT 函数正常工作。我可以用两个查询来完成,但我更喜欢做一个。
我希望你能帮助我。
谢谢。
P.S:我在答案 3 中提出了另一个问题。我快生气了!
最佳答案
试试
SELECT
AVG(tyd.price) AS avg_price, COUNT(tyd.id_product) AS cnt_id_p,
catalog.id_marchand, catalog.id_product, catalog.price AS c_price,
catalog.img_src, tyd.login AS tyd_l
FROM catalog
INNER JOIN tyd ON catalog.id_marchand = tyd.id_marchand
AND catalog.id_product = tyd.id_product
AND tyd.step = "0"
GROUP BY catalog.id_product, catalog.id_marchand
HAVING tyd.login = "[email protected]"
关于Sql,在逃避where条件的同时获取组的平均值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11740458/