HAVING without GROUP BY

后端 未结 4 1778
失恋的感觉
失恋的感觉 2020-11-28 13:13
  1. Is the following possible according to standard(!) SQL?
  2. What minimal changes should be neccessary in order to be conforming to the standard (if it wasn\'t alr
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 13:45

    From the standard (bold added from emphasis)

    1) Let HC be the having clause. Let TE be the table expression that immediately contains HC. If TE does not immediately contain a group by clause, then “GROUP BY ()” is implicit. Let T be the descriptor of the table defined by the GBC immediately contained in TE and let R be the result of GBC.

    With the implicit group by clause, the outer reference can access the TE columns.

    However, the certification to these standards is very much a self-certification these days, and the example you gave would not work across all of the main RDBMS providers.

提交回复
热议问题