我在使用mysql时遇到一些问题,在特定情况下,我在查询中获取随机值
select t.rango AS "Rango de Precios", AVG(comentarios.puntos) as Promedio
from
comentarios RIGHT JOIN juegos ON(comentarios.id_juego = juegos.id_juegos),
(select case
when precio = 0 then 'Gratis'
when precio > 0 and precio < 300 then 'De 0 a 300'
when precio > 300 and precio < 600 then 'De 300 a 600'
else 'Mayor a 600'
end
as rango,
precio
from juegos) as t
group by rango
我希望你能帮助我!
提前致谢!
编辑:我试图获得每个类别的平均分数(如果precio = 0,介于0和300之间等)
问题是我得到avg的随机值(comentarios.puntos)
我尝试像这样进行查询
我得到了回应
Rango de Precios Promedio
De 0 a 300 7.6667
De 300 a 600 7.6667
Gratis 7.6667
Mayor a 600 7.6667
我希望你能帮助我!非常感谢!
编辑:我使用没有子查询的情况解决了
SELECT (
CASE
when precio = 0 THEN ' 0$'
when precio between 0 and 300 then 'Entre 0$ y 300$'
when precio between 300 and 600 then 'Entre 300$ y 600$'
else 'Más de 600$'
end) as Rango,
AVG(comentarios.puntos) as 'Puntaje Promedio'
from juegos left join comentarios on(juegos.id_juegos = comentarios.id_juego)
group by Rango
谢谢你们!