views:

44

answers:

2

I'm creating a view as such:

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

But I'd like to create a calculated field on each row that does something like:

r.rating/COUNT(r.id)

Is there any way to do this?

A: 

Can't say anything about it's performance:

CREATE VIEW all 
AS 
SELECT 
    r.rating, r.id, r.rating / (SELECT COUNT(id) FROM riv_ratings) 
FROM  
    riv_ratings r 
Mitch Wheat
A: 

I figured it out, thanks.

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

Performance wise it is awful, but it gets the job done.

Pete