简体   繁体   中英

I have a problem ... subquery alias problem

select *, case 
when lagg is NULL then 'This student studies the most time' 
when hours_studied < lagg then 'This student studies ' || 
cast(lagg - hours_studied as string) || 'fewer than other' end details 
from (select students.*, lag(hours_studied) 
      over (PARTITION by school order by hours_studied desc) lagg 
      from students)  

when I execute the whole code then this happens.

ERROR: subquery in FROM must have an alias HINT: For example, FROM (SELECT...) [AS] foo.

select *, case 
when lagg is NULL then 'This student studies the most time' 
when hours_studied < lagg then 'This student studies ' || 
cast(lagg - hours_studied as string) || 'fewer than other' end details 
from (select students.*, lag(hours_studied) 
      over (PARTITION by school order by hours_studied desc) lagg 
      from students) x  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM