Skip to content

lesson_ratings

Like / dislike ratings on lessons by learners.

  • ETL strategy: merge
  • PK: id

Columns

ColumnTypeDescription
idBIGINTPK.
id_tenantBIGINTFK → tenants.id.
id_productBIGINTFK → products.id.
id_lessonBIGINTFK → lessons.id.
id_userBIGINTFK → users.id.
voteSMALLINTLike / dislike. Enum — see below.
created_atTIMESTAMPTZ

No deleted_at. To "remove" a rating, the system deletes the row (no soft-delete). Account for that when auditing.

Enum · vote

ValueMeaning
1Like (positive vote).
-1Dislike (negative vote).

Patterns

sql
-- Best-rated lessons
SELECT id_lesson,
       count(*)                              AS total,
       sum((vote =  1)::int)                 AS likes,
       sum((vote = -1)::int)                 AS dislikes,
       round(avg(vote)::numeric, 3)          AS score
FROM lms.lesson_ratings
GROUP BY id_lesson
HAVING count(*) >= 10
ORDER BY score DESC, total DESC;

A pre-aggregated view exists: metrics.lesson_rating_aggregates.

OpenDB · Cademi LMS Data Warehouse