godette/migrations/20250302015710_top_view.sql

16 lines
374 B
SQL

-- +goose Up
-- +goose StatementBegin
SELECT 'up SQL query';
CREATE VIEW IF NOT EXISTS total_karma AS SELECT u.id, u.name, sum(change) as total from karma
INNER JOIN users u ON u.id=karma.to_user
WHERE 1
GROUP BY u.id
ORDER BY total DESC;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
SELECT 'down SQL query';
DROP VIEW total_karma
-- +goose StatementEnd