子查询

利用子查询进行过滤

  1. select * from table where order_id in (2005,2007);

image.png

  1. select cust_name,cust_state,(select count(*) from orders where orders.cust_id = customers.cust_id) as orders from
  2. customers order by cust_name

image.png
上述语句什么意思呢?

根据cust_name排序,然后查看出每个cust_id在order出现了多少次,以及名称等信息