子查询
更新时间:
以下示例在WHERE子句中包含一个表子查询,该子查询生成多个行。在本示例中,行只包含一列,但表子查询可以包含多个列和行,就像任何其他表一样。
以下查询查找门票销量排名前10位的卖家。
select firstname, lastname, cityname, max(qtysold) as maxsoldfrom users join sales on users.userid=sales.selleridwhere users.city not in(select venuecity from venue)group by firstname, lastname, cityorder by maxsold desc, city desclimit 10;firstname | lastname | cityname | maxsold-----------+----------+----------------+---------Noah | Guerrero | Worcester | 8Isadora | Moss | Winooski | 8Kieran | Harrison | Westminster | 8Heidi | Davis | Warwick | 8Sara | Anthony | Waco | 8Bree | Buck | Valdez | 8Evangeline | Sampson | Trenton | 8Kendall | Keith | Stillwater | 8Bertha | Bishop | Stevens Point | 8Patricia | Anderson | South Portland | 8(10 rows)
该文章对您有帮助吗?