五好的Book - mysql window function
type: channel
link: http://www.opensoft.pw/tag/mysql-window-function/
items: You cannot use the alias '' of an expression containing a window function in this context.

You cannot use the alias '' of an expression containing a window function in this context.
type: item
date: 2021-11-24T07:20:44+00:00
description: 抛出这个错误一般是你使用窗口函数后直接在where子句里引用了窗口函数的结果，但是窗口函数的计算是在where子句之后才执行的，所以sql会抛出异常 ，那么该怎么解决这个问题呢？1.使用子查询2.使用 with的方法如：子查询的方式select title,(select name from clas where id=top.cid)cname,view from (SELECT title,cid,view,row_number () over ( PARTITION BY `cid` ORDER BY view desc ) t from book)top where t=1 with的方式with top as( SELECT title,cid,view,row_number () over ( PARTITION BY `cid` ORDER BY view desc ) t from book) select title,(select name from clas where id=top.cid)cname,view from top where t=1; 上述语句是从数据库中查询每个分类中点击最多的书，由此可以优雅的看出各个分类中那一本书最受欢迎。而如果我们使用group by 来做类似的求值 一般会出现only_full_group_by的错误提示，而且也不好处理