Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
avg with subquery
--PostgreSQL 9.5 CREATE TABLE apps(id serial PRIMARY KEY, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, published BOOLEAN, mean_rating FLOAT); INSERT INTO apps(published) VALUES (true), (true), (true), (false); CREATE TABLE reviews(id serial PRIMARY KEY, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, comment TEXT, app_id INT, rating FLOAT DEFAULT 0, CHECK (rating BETWEEN 0 AND 5)); INSERT INTO reviews(app_id, rating) VALUES (1, 2), (1, 3), (2, 3), (4, 5); UPDATE apps SET mean_rating = (SELECT AVG(rating) FROM reviews WHERE reviews.app_id = apps.id); SELECT * FROM apps;
run
|
edit
|
history
|
help
0
Ultima Clase
Professional Networking Social Media Website SQL Analysis
statistics
array comparison
Professional Networking Social Media Website SQL Analysis
Many to many
simple add function on sql
SQL - Unpivot Table
post
first