Search code examples
mysqlsqlrelational-algebra

Relational Algebra SQL


Hello everyone i was wondering if i could get some help with a problem

Postimi(status)(Post_ID:integer,user_ID:integer,test:string, data:date,time:integer)

I need to fing the Relational Algebra related to Postimi

the question is

List users who posted two or more statuses yesterday while today have not posted any statuses?

if someone could help me. Thank you in Advance


Solution

  • select yd.user_ID
    from status yd -- yd for yesterday
    where yd.date = current_date() - interval 1 day
    and not exists (
      select *
      from status td -- td for today
      where td.user_ID = yd.user_ID
        and td.date = current_date()
    )
    group by yd.user_ID
    having count(*) >= 2
    

    Or

    select user_ID
    from status
    where date >= current_date() - interval 1 day
      and date <= current_date()
    group by user_ID
    having count(*) >= 2
       and max(date) < current_date()