Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MYSQL-- subquery

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report