1

我正在创建这样的视图:

CREATE VIEW all AS
SELECT m.id, m.title, m.description, m.date, m.views, r.rating, r.id
FROM riv_montage m, riv_ratings r

但我想在每一行上创建一个计算字段,它执行以下操作:

r.rating/COUNT(r.id)

有没有办法做到这一点?

4

2 回答 2

1

我想通了,谢谢。

SELECT m.id, m.title, m.description, m.date, m.views,
(SELECT SUM(rating) FROM riv_ratings WHERE id = m.id) / (SELECT COUNT(*) FROM riv_ratings WHERE id = m.id) AS calc
FROM riv_montage m

性能方面它很糟糕,但它完成了工作。

于 2010-08-11T15:53:43.893 回答
0

不能说它的性能:

CREATE VIEW all 
AS 
SELECT 
    r.rating, r.id, r.rating / (SELECT COUNT(id) FROM riv_ratings) 
FROM  
    riv_ratings r 
于 2010-08-11T15:04:24.023 回答