推特 阿里云技术文档正文

子查询_SELECT_SQL手册_分析型数据库MySQL版

admin 阿里云技术文档 2020-02-11 177 0
阿里云服务器优惠

子查询

以下示例查询门票销量排名前10的卖家,WHERE子句中包含一个表子查询,子查询生成多个行,每行包含一列数据。

表子查询可以包含多个列和行。

  1. select firstname, lastname, cityname, max(qtysold) as maxsold
  2. from users join sales on users.userid=sales.sellerid
  3. where users.cityname not in(select venuecity from venue)
  4. group by firstname, lastname, cityname
  5. order by maxsold desc, cityname desc
  6. limit 10;
  7. firstname | lastname | cityname | maxsold
  8. -----------+----------+----------------+---------
  9. Noah | Guerrero | Worcester | 8
  10. Isadora | Moss | Winooski | 8
  11. Kieran | Harrison | Westminster | 8
  12. Heidi | Davis | Warwick | 8
  13. Sara | Anthony | Waco | 8
  14. Bree | Buck | Valdez | 8
  15. Evangeline | Sampson | Trenton | 8
  16. Kendall | Keith | Stillwater | 8
  17. Bertha | Bishop | Stevens Point | 8
  18. Patricia | Anderson | South Portland | 8
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论

-----