子查询返回的结果当做数据源来使用. 语法:#单表 select list from tab_name .... select list from (select expression) alias_name ... #MySQL内联视图必须有别名 #连接 select list from left_tab join_type right_tab on join_condition ... select list from (select expression) alias_name join_type (select expression) alias_name on join_condition ...
#哪些用户购买了市场价格大于2000的商品 SELECT * FROM ecs_users; SELECT * FROM ecs_order_info; SELECT * FROM ecs_order_goods; #SELECT * FROM ecs_goods; SELECT u.user_id, u.user_name, t.goods_name, t.market_price FROM(ecs_users u INNER JOIN ecs_order_info oi ON u.user_id = oi.user_id )INNER JOIN(SELECT * FROM ecs_order_goods og WHERE og.market_price > 2000) t ON oi.order_id = t.order_id;