我有这种表(例如..在我的情况下,这个表有超过60000条记录)
我想知道如何制作一个选择以获得更高费率的movieId(或songId)的性别比率?
我这样查询:
select * from
(
SELECT avg(rating)as rating, movieID,'M' as gender FROM [OF7.TEST]
where gender = 'M'
group by movieID
) ,
(
SELECT avg(rating)as rating, movieID,'F' as gender FROM [OF7.TEST]
where gender = 'F'
group by movieID
)
order by movieId
获得这个结果之王:
问题是: 性别之间是否存在差异,哪些 性别比率较高的电影,这种差异是否显着?
谢谢
答案 0 :(得分:2)
我之前从未使用过bigquery,但是这样的事情应该有效:
SELECT movieID,
CASE
WHEN F_rate >= M_rate THEN F_rate
ELSE M_rate
END max_rating,
CASE
WHEN F_rate > M_rate THEN 'Females Rated it Higher'
WHEN F_rate < M_rate THEN 'Males Rated it Higher'
ELSE 'Rated Equal'
END AS who_rated_it_higher,
ABS(F_rate - M_rate) --absolute value of difference
FROM
(
SELECT movieID,
AVG(CASE WHEN gender = 'F' THEN rating END) AS F_rate,
AVG(CASE WHEN gender = 'M' THEN rating END) AS M_rate
FROM CTE
GROUP BY MovieID
) AS A
如果您有任何问题或需要其他任何问题,请告诉我。