mysql必知必会题⽬_MYSQL必知必会挑战题答案
SQL
sql语句执⾏顺序
(8) SELECT
(9)DISTINCT
(1) FROM
(3) JOIN
(2) ON
(4) WHERE
(5) GROUP BY
(6) WITH {CUBE|ROLLUP}
(7) HAVING
(10) ORDER BY
(11) LIMIT
(1) FROM:对FROM⼦句中的左表和右表执⾏笛卡⼉积,产⽣虚拟表VT1;
(2) ON: 对虚拟表VT1进⾏ON筛选,只有那些符合的⾏才被插⼊虚拟表VT2;
(3) JOIN: 如果指定了OUTER JOIN(如LEFT OUTER JOIN、RIGHT OUTER JOIN),那么保留表中未匹配的⾏作为外部⾏添加到虚拟表VT2,产⽣虚拟表VT3。
如果FROM⼦句包含两个以上的表,则对上⼀个连接⽣成的结果表VT3和下⼀个表重复执⾏步骤1~步骤3,直到处理完所有的表;forward是正品吗
mysql语句顺序(4) WHERE: 对虚拟表VT3应⽤WHERE过滤条件,只有符合的记录才会被插⼊虚拟表VT4;
(5) GROUP By: 根据GROUP BY⼦句中的列,对VT4中的记录进⾏分组操作,产⽣VT5;
(6) CUBE|ROllUP: 对VT5进⾏CUBE或ROLLUP操作,产⽣表VT6;
(7) HAVING: 对虚拟表VT6应⽤HAVING过滤器,只有符合的记录才会被插⼊到VT7;
(8) SELECT: 第⼆次执⾏SELECT操作,选择指定的列,插⼊到虚拟表VT8中;
(9) DISTINCT: 去除重复,产⽣虚拟表VT9;
(10) ORDER BY: 将虚拟表VT9中的记录按照进⾏排序操作,产⽣虚拟表VT10;
(11) LIMIT: 取出指定街⾏的记录,产⽣虚拟表VT11,并返回给查询⽤户
SELECT
Persons.LastName,
Persons.FirstName,
Orders.OrderNo
FROM
Persons.Id_P = Orders.Id_P
SELECT
Persons.LastName,
Persons.FirstName,
Orders.OrderNo
FROM
Persons
INNER JOIN Orders ON
Persons.Id_P = Orders.Id_P
ORDER BY
Persons.LastName
除了我们在上⾯的例⼦中使⽤的 INNER JOIN(内连接),我们还可以使⽤其他⼏种连接。下⾯列出了您可以使⽤的 JOIN 类型,以及它们之间的差异。
JOIN: 如果表中有⾄少⼀个匹配,则返回⾏
INNER JOIN 与 JOIN 是相同的。
LEFT JOIN: 即使右表中没有匹配,也从左表返回所有的⾏
RIGHT JOIN: 即使左表中没有匹配,也从右表返回所有的⾏
FULL JOIN: 只要其中⼀个表中存在匹配,就返回⾏
UPDATE
表名
set
VALUES1 = 'xxx',
VALUE2 = 'xxxxx';
insert
into
表名(value1, value2)
mysql交集values ('xx', 'xx')
createtextfile utf8
---从某个表中查询数据,插⼊另外的表中
insert
into
table1(value1, 2)
FROM
table2
--复制整个表
SELECT
*
INTO
OrdersBackup
FROM
Orders;
CREATE TABLE OrdersBackup AS
SELECT
*
FROM
Orders;
最详细的多线程
--where较select先执⾏,要使⽤select中的别名,解决⽅法是将含有别名列的查询放⼊内嵌视图,就可以在外层查询中引⽤别名列。内嵌视图的别名为 X
select
*
from
(
select
ID as i, goodsno as no_1
from
ALU_ss )x
where
i = '1';
select
prod_name,
prod_desc
from
products
and prod_desc LIKE '%carrots%';
select
prod_name,
prod_desc
from
products
where
prod_desc LIKE '%toy%carrots%';
select
vend_id,
vend_name as vname,
vend_address as vaddress,
vend_city as vcity
from
vendors
order by
vend_name;
select
prod_id,
prod_price,
prod_price*0.9 as sale_price
from
products;
--复制表数据,已经建好了表结构,该语句只能复制表的结构。该语句不会创建和复制源相同的主键、索引、约束和触发器。INSERT
into
newtable
select
name,sex ---COLUMN
FROM
sourcetable;
--复制表和表结构。该语句不会创建和复制源相同的主键、索引、约束和触发器。
newtables
from
sourcetables
where
whereexpression;
select
cust_id,
customer_name,
CONCAT(UPPER(LEFT(cust_contact, 2)), LEFT(cust_city, 3)))as user_login from
customers;
select
php设计源码order_num,
order_data
from
orders
where
year(order_data)= 2020
and month(order_data) = 1;
select
SUM(quantity)
from
orderitems;
select
SUM(quantity)
from
orderitems
where
prod_item = 'BR01';
select
MAX(prod_price) as max_price
from

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。