1. 程式人生 > >sql 標量子查詢

sql 標量子查詢

返回結果只有一行的查詢叫標量子查詢.

SELECT shohin_mei shohin_bunrui FROM Shohin WHERE hanbai_tanka > (SELECT AVG(hanbai_tanka) FROM Shohin);

標量子查詢可以和列一樣

mysql> SELECT shohin_id ,shohin_mei,shohin_bunrui,\

    -> (SELECT AVG(hanbai_tanka) FROM Shohin) AS avg_tanka\

    -> FROM Shohin;