Home > Backend Development > PHP Tutorial > Something happened today-MySQL, something happened-MySQL_PHP tutorial

Something happened today-MySQL, something happened-MySQL_PHP tutorial

WBOY
Release: 2016-07-12 09:05:42
Original
864 people have browsed it

Something happened today-MySQL, something happened-MySQL

 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 statements

Note: 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1068255.htmlTechArticleI have something to do today - MySQL, something to do - MySQL hi I have something to do today, I will go play soon, I will learn as much as I can 1 , MySQL -----Subquery and Connection (2)----- ----Subquery Subquery refers to the occurrence...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template