在where子句中使用别名的SQL

在where子句中使用别名的SQL,sql,where,alias,Sql,Where,Alias,我知道别名不起作用,但无法计算得到预期的结果和count\u of_circs=circ\u limit select libraryid, patronid, count(circ.id) as count_of_circs, ( select account.circsperpatronmonth from account w

我知道别名不起作用,但无法计算得到预期的结果和count\u of_circs=circ\u limit

    select libraryid,
           patronid,
           count(circ.id) as count_of_circs,
           (
               select account.circsperpatronmonth 
               from account 
               where circ.libraryid = account.libraryid
           ) as circ_limit
    from circ
    where borrowed >= '2014-04-01'
    and borrowed < '2014-04-19'
    and count_of_circs = circ_limit

    group by patronid,libraryid
您需要having子句:


您需要在group by之后添加一行

HAVING count_of_circs = circ_limit

它不是别名,而是在分组后进行筛选。

这是用于什么数据库的?您能解释一下您的表吗?
HAVING count_of_circs = circ_limit