select子句后只能放置标量子查询,要求每次只能返回一个值. 语法: select ... (select expression) ... from tabs where search_condition order by sort_columns;
#列出商品表中各商品的类型名称 SELECT goods_id, (SELECT cat_name FROM ecs_goods_type WHERE cat_id = g.goods_type) AS type_name, goods_name FROM ecs_goods g ORDER BY 2; #模拟Oracle的rownum(行编号) SELECT (SELECT COUNT(*) FROM ecs_goods e WHERE e.goods_id <= g.goods_id) AS rownum, goods_id, goods_name FROM ecs_goods g ORDER BY 1;