MYSQL-- subquery
Subquery of MYSQL
1 find the average value
SELECT AVG (field such as good_price) FROM tdb_ table name
2 round the result of the average value and keep the two places after the decimal point
SELECT ROUND (AVG (field),) FROM tdb_ table name
3 which of the average prices in the query field are greater than or equal to the average I want to compare
The first kind of SELECT field, field, field FROM tdb_ table name WHERE price field > = average
The second subquery SELECT field, field, field FROM tdb_ table name WHERE price field > = (SELECT ROUND (AVG (field),) FROM tdb_ table name)
In fact, multi-table update is divided into three steps. Categories in the query table 2. Write the query results to data Table 3. Multi-table update
4 categories in the query table
SELECT column name (such as goods_cate) FROM tdb_ table name GROUP BY column name
5 write the query results to the data table
INSERT tdb_ table name _ cates (cate_name) SELECT column name FROM tdb_ table name GROUP BY column name
6 multiple table updates (update your own table with reference to another table)
Step 1: UPDATE tdb_ table name INNER JOIN tdb_ column name (e.g. goods_cates) ON column name (goods_cate) = column name (cate_name); (click to confirm)
Step 2 SET column name (good_cate) = column name (cate_id)