hi
I have something to do today, I have to play for a while, I can learn as much as I can
1. MySQL
-----Subquery and Connection (2)-----
----Subquery
Subquery refers to the SELECT clause
that appears in other SQL statementsNote: A subquery is nested inside a query and must always appear within parentheses; it can contain multiple keywords or conditions; the outer query can be SELECT, INSERT, UPDATE, SET or DO
The return of the subquery can be a scalar, a row, a column or a subquery
can be divided into three categories: using comparison operators =, >=, etc.; NOT IN; EXIST
----Use comparison operators to implement subqueries
--
mysql> SELECT goods_id,goods_name,goods_price FROM tdb_goods WHERE goods_price>=5391.30;
You can ignore the number here, it is an average value obtained previously.
So if you want to directly get the result of the average value, use a subquery to write like this
mysql> SELECT goods_id,goods_name,goods_price FROM tdb_goods WHERE goods_price>=(SELECT ROUND(AVG(goods_price),2) FROM tdb_goods);
Here you can see that the subquery is in parentheses, using >=
--
When the subquery returns multiple results, but the main query does not use so many results, you can use the ANY SOME ALL keyword
ANY is the same as SOME. Just satisfy one of them. The specific one depends on the operator (for example, > is greater than the minimum value)
ALL requires that all returned requirements be met
Usage is written in front of the subquery parentheses
----Subquery triggered by IN or NOT IN
In fact, IN is equivalent to the =ALL operator, and NOT IN is equivalent to =! ALL equivalent
Usage is also similar
----EXIST
Returns a Boolean value, rarely used