735 lines
14 KiB
Markdown
735 lines
14 KiB
Markdown
|
<!-- GFM-TOC -->
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD>ѯ](#<23><>ѯ)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#ͨ<><CDA8><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>](#<23><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD>ʱ<EFBFBD>䴦<EFBFBD><EFBFBD>](#<23><><EFBFBD>ں<EFBFBD>ʱ<EFBFBD>䴦<EFBFBD><E4B4A6>)
|
|||
|
* [<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD>Ӳ<EFBFBD>ѯ](#<23>Ӳ<EFBFBD>ѯ)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>ѯ](#<23><><EFBFBD>ϲ<EFBFBD>ѯ)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD>)
|
|||
|
* [ɾ<EFBFBD><EFBFBD>](#ɾ<><C9BE>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD>ı<EFBFBD>](#<23>ı<DEB8>)
|
|||
|
* [<EFBFBD><EFBFBD>ͼ](#<23><>ͼ)
|
|||
|
* [<EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD>)
|
|||
|
* [<EFBFBD>α<EFBFBD>](#<23>α<EFBFBD>)
|
|||
|
* [<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>](#<23><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||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ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
SQL<EFBFBD><EFBFBD>Structured Query Language)<29><><EFBFBD><EFBFBD> SQL <20><> ANSI <20><>ίԱ<CEAF><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD>Ϊ ANSI SQL<51><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DBMS <20><><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD> PL/SQL<51><4C>Transact-SQL <20>ȡ<EFBFBD>
|
|||
|
|
|||
|
# <20><>ѯ
|
|||
|
|
|||
|
SQL <20><><EFBFBD>䲻<EFBFBD><E4B2BB><EFBFBD>ִ<EFBFBD>Сд<D0A1><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><DABE><EFBFBD><EFBFBD><EFBFBD> DBMS <20>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>á<EFBFBD>
|
|||
|
|
|||
|
**DISTINCT**
|
|||
|
|
|||
|
<EFBFBD><EFBFBD>ֵֻͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>Ρ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT DISTINCT col1, col2
|
|||
|
FROM mytable;
|
|||
|
```
|
|||
|
|
|||
|
**LIMIT**
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ʼ<EFBFBD>У<EFBFBD><EFBFBD><EFBFBD> 0 <20><>ʼ<EFBFBD><CABC><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ 5 <20>е<EFBFBD> SQL<51><4C>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT *
|
|||
|
FROM mytable
|
|||
|
LIMIT 5;
|
|||
|
```
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT *
|
|||
|
FROM mytable
|
|||
|
LIMIT 0, 5;
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD> 3 \~ 5 <20>У<EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT *
|
|||
|
FROM mytable
|
|||
|
LIMIT 2, 3;
|
|||
|
```
|
|||
|
|
|||
|
**ע<><D7A2>**
|
|||
|
|
|||
|
```sql
|
|||
|
# ע<><D7A2>
|
|||
|
SELECT *
|
|||
|
FROM mytable -- ע<><D7A2>
|
|||
|
/* ע<><D7A2>1
|
|||
|
ע<><D7A2>2 */
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
**ASC**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϣ<EFBFBD>
|
|||
|
**DESC**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT *
|
|||
|
FROM mytable
|
|||
|
ORDER BY col1 DESC, col2 ASC;
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD><EFBFBD>й<EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷdz<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>紫<EFBFBD><EFBFBD><EFBFBD>˺ܶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT *
|
|||
|
FROM mytable
|
|||
|
WHERE col IS NULL;
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD>±<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD> WHERE <20>Ӿ<EFBFBD><D3BE><EFBFBD><EFBFBD>õIJ<C3B5><C4B2><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
| <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ˵<><CBB5> |
|
|||
|
| ------------ | ------------ |
|
|||
|
| = < > | <20><><EFBFBD><EFBFBD> С<><D0A1> <20><><EFBFBD><EFBFBD> |
|
|||
|
| <> != | <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|||
|
| <= !> | С<>ڵ<EFBFBD><DAB5><EFBFBD> |
|
|||
|
| >= !< | <20><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD> |
|
|||
|
| BETWEEN | <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ֮<D6B5><D6AE> |
|
|||
|
| IS NULL | ΪNULLֵ |
|
|||
|
|
|||
|
Ӧ<EFBFBD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EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
# ͨ<><CDA8><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>ֶΡ<EFBFBD>
|
|||
|
|
|||
|
- **%** ƥ<><C6A5> >=0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \*<2A><>
|
|||
|
|
|||
|
- **\_** ƥ<><C6A5> ==1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> \.<2E><>
|
|||
|
|
|||
|
- **[ ]** <20><><EFBFBD><EFBFBD>ƥ<EFBFBD>伯<EFBFBD><E4BCAF><EFBFBD>ڵ<EFBFBD><DAB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD> ^ <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD>
|
|||
|
|
|||
|
ʹ<EFBFBD><EFBFBD> Like <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>ƥ<EFBFBD>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BFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʹ<EFBFBD><EFBFBD> **AS** <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT col1*col2 AS alias
|
|||
|
FROM mytable
|
|||
|
```
|
|||
|
|
|||
|
**Concat()** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶΡ<D6B6><CEA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>ʹ<EFBFBD>ÿո<C3BF><D5B8><EFBFBD>һ<EFBFBD><D2BB>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ<EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵĽ<D3B5><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB><D0A9><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ŀո<C4BF><D5B8><EFBFBD>ʹ<EFBFBD><CAB9> **TRIM()** <20><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>β<EFBFBD>ո<EFBFBD><D5B8><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT Concat(TRIM(col1), ' (', TRIM(col2), ')')
|
|||
|
FROM mytable
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> DBMS <20>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD>ͬ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2>
|
|||
|
|
|||
|
## <20>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
| <20><><EFBFBD><EFBFBD> | ˵<><CBB5> |
|
|||
|
| ------------ | ------------ |
|
|||
|
| LEFT() RIGHT() | <20><><EFBFBD><EFBFBD><DFBB><EFBFBD><EFBFBD>ұߵ<D2B1><DFB5>ַ<EFBFBD> |
|
|||
|
| LOWER() UPPER() | ת<><D7AA>ΪСд<D0A1><D0B4><EFBFBD>ߴ<EFBFBD>д |
|
|||
|
| LTRIM() RTIM() | ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBB><EFBFBD><EFBFBD>ұߵĿո<C4BF> |
|
|||
|
| LENGTH() | <20><><EFBFBD><EFBFBD> |
|
|||
|
| SUNDEX() | ת<><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ֵ |
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>**SOUNDEX()** <20>ǽ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD>㷨<EFBFBD><E3B7A8><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>Ƚϡ<C8BD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT *
|
|||
|
FROM mytable
|
|||
|
WHERE SOUNDEX(col1) = SOUNDEX('apple')
|
|||
|
```
|
|||
|
## <20><><EFBFBD>ں<EFBFBD>ʱ<EFBFBD>䴦<EFBFBD><E4B4A6>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD>ʽ<EFBFBD><EFBFBD>YYYY-MM-DD
|
|||
|
|
|||
|
ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>HH:MM:SS
|
|||
|
|
|||
|
|<7C><> <20><> | ˵ <20><>|
|
|||
|
| --- | --- |
|
|||
|
| AddDate() | <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3>졢<EFBFBD>ܵȣ<DCB5>|
|
|||
|
| AddTime() | <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD>䣨ʱ<E4A3A8><CAB1><EFBFBD>ֵȣ<D6B5>|
|
|||
|
| CurDate() | <20><><EFBFBD>ص<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD> |
|
|||
|
| CurTime() | <20><><EFBFBD>ص<EFBFBD>ǰʱ<C7B0><CAB1> |
|
|||
|
|Date() |<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>|
|
|||
|
|DateDiff() |<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE>|
|
|||
|
|Date_Add() |<7C>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㺯<EFBFBD><E3BAAF>|
|
|||
|
|Date_Format() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ʱ<EFBFBD>䴮|
|
|||
|
|Day()| <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|
|
|||
|
|DayOfWeek() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>|
|
|||
|
|Hour() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Сʱ<D0A1><CAB1><EFBFBD><EFBFBD>|
|
|||
|
|Minute() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD>ķ<EFBFBD><C4B7>Ӳ<EFBFBD><D3B2><EFBFBD>|
|
|||
|
|Month() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5>·ݲ<C2B7><DDB2><EFBFBD>|
|
|||
|
|Now() |<7C><><EFBFBD>ص<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ں<EFBFBD>ʱ<EFBFBD><CAB1>|
|
|||
|
|Second() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>벿<EFBFBD><EBB2BF>|
|
|||
|
|Time() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʱ<EFBFBD>䲿<EFBFBD><E4B2BF>|
|
|||
|
|Year() |<7C><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD>|
|
|||
|
|
|||
|
```sql
|
|||
|
mysql> SELECT NOW();
|
|||
|
-> '2017-06-28 14:01:52'
|
|||
|
```
|
|||
|
|
|||
|
## <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
| <20><><EFBFBD><EFBFBD> | ˵<><CBB5> |
|
|||
|
| --- | --- |
|
|||
|
| SIN() | <20><><EFBFBD><EFBFBD> |
|
|||
|
|COS() | <20><><EFBFBD><EFBFBD> |
|
|||
|
| TAN() | <20><><EFBFBD><EFBFBD> |
|
|||
|
| ABS() | <20><><EFBFBD><EFBFBD>ֵ |
|
|||
|
| SQRT() | ƽ<><C6BD><EFBFBD><EFBFBD>|
|
|||
|
| MOD() | <20><><EFBFBD><EFBFBD>|
|
|||
|
| EXP() | ָ<><D6B8>|
|
|||
|
| PI() | Բ<><D4B2><EFBFBD><EFBFBD>|
|
|||
|
|RAND() | <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|
|
|||
|
|
|||
|
## <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
|<7C><> <20><> |˵ <20><>|
|
|||
|
| --- | --- |
|
|||
|
|AVG() |<7C><><EFBFBD><EFBFBD>ij<EFBFBD>е<EFBFBD>ƽ<EFBFBD><C6BD>ֵ|
|
|||
|
|COUNT()| <20><><EFBFBD><EFBFBD>ij<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>|
|
|||
|
|MAX()| <20><><EFBFBD><EFBFBD>ij<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>ֵ|
|
|||
|
|MIN()| <20><><EFBFBD><EFBFBD>ij<EFBFBD>е<EFBFBD><D0B5><EFBFBD>Сֵ|
|
|||
|
|SUM() |<7C><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ֵ֮<D6B5><D6AE>|
|
|||
|
|
|||
|
AVG() <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <20>С<EFBFBD>
|
|||
|
|
|||
|
DISTINCT <20>ؼ<EFBFBD><D8BC>ֻ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ܲ<EFBFBD>ͬ<EFBFBD><CDAC>ֵ<EFBFBD><D6B5>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT AVG(DISTINCT col1) AS avg_col
|
|||
|
FROM mytable
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD><EFBFBD>ͬһ<EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>û<EFBFBD><EFBFBD>ܺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD>ֵ<EFBFBD>ȡ<EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD> col <20><><EFBFBD><EFBFBD><F2B2A2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT col, COUNT(*) AS num
|
|||
|
FROM mytable
|
|||
|
GROUP BY col;
|
|||
|
```
|
|||
|
|
|||
|
WHERE <20><><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>HAVING <20><><EFBFBD>˷<EFBFBD><CBB7>飬<EFBFBD>й<EFBFBD><D0B9><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT col, COUNT(*) AS num
|
|||
|
FROM mytable
|
|||
|
WHERE col > 2
|
|||
|
GROUP BY col
|
|||
|
HAVING COUNT(*) >= 2;
|
|||
|
```
|
|||
|
|
|||
|
GROUP BY <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3><EFBFBD> ORDER BY Ҳ<><D2B2><EFBFBD><EFBFBD><EFBFBD>Ծۼ<D4BE><DBBC>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT col, COUNT(*) AS num
|
|||
|
FROM mytable
|
|||
|
GROUP BY col
|
|||
|
ORDER BY num;
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>涨<EFBFBD><EFBFBD>
|
|||
|
|
|||
|
1. GROUP BY <20>Ӿ<EFBFBD><D3BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WHERE <20>Ӿ<EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>ORDER BY <20>Ӿ<EFBFBD>֮ǰ<D6AE><C7B0>
|
|||
|
2. <20><><EFBFBD>˻<EFBFBD><CBBB>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD>⣬SELECT <20><><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ÿһ<C3BF>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GROUP BY <20>Ӿ<EFBFBD><D3BE>и<EFBFBD><D0B8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
3. NULL <20><><EFBFBD>лᵥ<D0BB><E1B5A5><EFBFBD><EFBFBD>Ϊһ<CEAA>飻
|
|||
|
4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SQL ʵ<>ֲ<EFBFBD>֧<EFBFBD><D6A7> GROUP BY <20>о<EFBFBD><D0BE>пɱ䳤<C9B1>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>
|
|||
|
|
|||
|
# <20>Ӳ<EFBFBD>ѯ
|
|||
|
|
|||
|
<EFBFBD>Ӳ<EFBFBD>ѯ<EFBFBD><EFBFBD>ֻ<EFBFBD>ܷ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD>Ӳ<EFBFBD>ѯ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ WHRER <20><><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```
|
|||
|
SELECT *
|
|||
|
FROM mytable1
|
|||
|
WHERE col1 IN (SELECT col2
|
|||
|
FROM mytable2);
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD>ִ<EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT cust_name, (SELECT COUNT(*)
|
|||
|
FROM Orders
|
|||
|
WHERE Orders.cust_id = Customers.cust_id)
|
|||
|
AS orders_num
|
|||
|
FROM Customers
|
|||
|
ORDER BY cust_name;
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFB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|
|
|||
|
## <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳƵ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>ʹ<EFBFBD><EFBFBD> INNER JOIN <20>ؼ<EFBFBD><D8BC>֡<EFBFBD>
|
|||
|
|
|||
|
```
|
|||
|
select a, b, c
|
|||
|
from A inner join B
|
|||
|
on A.key = B.key
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><EFBFBD><EFBFBD>ȷʹ<EFBFBD><EFBFBD> INNER JOIN<49><4E><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD> WHERE <20>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>õ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```
|
|||
|
select a, b, c
|
|||
|
from A, B
|
|||
|
where A.key = B.key
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>صѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
## <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>һ<EFBFBD>֣<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>
|
|||
|
|
|||
|
һ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>Ҫ<EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD> Jim <20><><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
**<2A>Ӳ<EFBFBD>ѯ<EFBFBD>汾**
|
|||
|
|
|||
|
```
|
|||
|
select name
|
|||
|
from employee
|
|||
|
where department = (
|
|||
|
select department
|
|||
|
from employee
|
|||
|
where name = "Jim");
|
|||
|
```
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD><EFBFBD>Ӱ汾**
|
|||
|
|
|||
|
```
|
|||
|
select name
|
|||
|
from employee as e1, employee as e2
|
|||
|
where e1.department = e2.department
|
|||
|
and e1.name = "Jim";
|
|||
|
```
|
|||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><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD>
|
|||
|
|
|||
|
```
|
|||
|
select *
|
|||
|
from employee natural join department;
|
|||
|
```
|
|||
|
|
|||
|
## <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й˿͵Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>Ĺ˿͡<EFBFBD>
|
|||
|
|
|||
|
```
|
|||
|
select Customers.cust_id, Orders.order_num
|
|||
|
from Customers left outer join Orders
|
|||
|
on Customers.cust_id = Orders.curt_id
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫͳ<EFBFBD>ƹ˿͵Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>þۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```
|
|||
|
select Customers.cust_id,
|
|||
|
COUNT(Orders.order_num) as num_ord
|
|||
|
from Customers left outer join Orders
|
|||
|
on Customers.cust_id = Orders.curt_id
|
|||
|
group by Customers.cust_id
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD>ϲ<EFBFBD>ѯ
|
|||
|
|
|||
|
ʹ<EFBFBD><EFBFBD> **UNION** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>߾ۼ<DFBE><DBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
Ĭ<EFBFBD>ϻ<EFBFBD>ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>У<EFBFBD>ʹ<EFBFBD><EFBFBD> UNION ALL <20><>
|
|||
|
|
|||
|
ֻ<EFBFBD>ܰ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> ORDER BY <20>Ӿ䣬<D3BE><E4A3AC><EFBFBD>ұ<EFBFBD><D2B1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT col
|
|||
|
FROM mytable
|
|||
|
WHERE col = 1
|
|||
|
UNION
|
|||
|
SELECT col
|
|||
|
FROM mytable
|
|||
|
WHERE col =2;
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
**<2A><>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
INSERT INTO mytable(col1, col2)
|
|||
|
VALUES(val1, val2);
|
|||
|
```
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
INSERT INTO mytable1(col1, col2)
|
|||
|
SELECT col1, col2
|
|||
|
FROM mytable2;
|
|||
|
```
|
|||
|
|
|||
|
**<2A><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8>Ƶ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>±<EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
CREATE TABLE newtable AS
|
|||
|
SELECT * FROM mytable;
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
UPDATE mytable
|
|||
|
SET col = val
|
|||
|
WHERE id = 1;
|
|||
|
```
|
|||
|
|
|||
|
# ɾ<><C9BE>
|
|||
|
|
|||
|
```sql
|
|||
|
DELETE FROM mytable
|
|||
|
WHERE id = 1;
|
|||
|
```
|
|||
|
|
|||
|
**TRUNCATE TABLE** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ<EFBFBD><D5B1><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
|||
|
|
|||
|
ʹ<EFBFBD>ø<EFBFBD><EFBFBD>º<EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱһ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD> WHERE <20>Ӿ䣬<D3BE><E4A3AC>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SELECT <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2>ԣ<EFBFBD><D4A3><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
CREATE TABLE mytable (
|
|||
|
id INT NOT NULL AUTO_INCREMENT,
|
|||
|
col1 INT NOT NULL DEFAULT 1,
|
|||
|
col2 VARCHAR(45) NULL,
|
|||
|
col3 DATE NULL,
|
|||
|
PRIMARY KEY (`id`));
|
|||
|
```
|
|||
|
|
|||
|
# <20>ı<DEB8>
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
ALTER TABLE mytable
|
|||
|
ADD col CHAR(20);
|
|||
|
```
|
|||
|
|
|||
|
**ɾ<><C9BE><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
ALTER TABLE mytable
|
|||
|
DROP COLUMN col;
|
|||
|
```
|
|||
|
|
|||
|
**ɾ<><C9BE><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
DROP TABLE mytable;
|
|||
|
```
|
|||
|
|
|||
|
# <20><>ͼ
|
|||
|
|
|||
|
<EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>Ҳ<EFBFBD>Ͳ<EFBFBD><EFBFBD>ܶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ºô<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
1. <20><EFBFBD><F2BBAFB8>ӵ<EFBFBD> SQL <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>縴<EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>
|
|||
|
2. ֻʹ<D6BB><CAB9>ʵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>
|
|||
|
3. ͨ<><CDA8>ֻ<EFBFBD><D6BB><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>Ȩ<EFBFBD>ޣ<EFBFBD><DEA3><EFBFBD>֤<EFBFBD><D6A4><EFBFBD>ݵİ<DDB5>ȫ<EFBFBD>ԣ<EFBFBD>
|
|||
|
4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ<EFBFBD>ͱ<EFBFBD>ʾ<EFBFBD><CABE>
|
|||
|
|
|||
|
```sql
|
|||
|
CREATE VIEW myview AS
|
|||
|
SELECT Concat(col1, col2) AS concat_col, col3*col4 AS count_col
|
|||
|
FROM mytable
|
|||
|
WHERE col5 = val;
|
|||
|
```
|
|||
|
|
|||
|
# <20>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD>̿<EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>һϵ<EFBFBD><EFBFBD> SQL <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
**ʹ<>ô洢<C3B4><E6B4A2><EFBFBD>̵ĺô<C4BA>**
|
|||
|
|
|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BFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>ַֺŵ<D6BA><C5B5><EFBFBD><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB7A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> in<69><6E>out <20><> inout <20><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD> select into <20><><EFBFBD>䡣
|
|||
|
|
|||
|
ÿ<EFBFBD><EFBFBD>ֻ<EFBFBD>ܸ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ּ<EFBFBD><EFBFBD>ϵIJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
delimiter //
|
|||
|
|
|||
|
create procedure myprocedure( out ret int )
|
|||
|
begin
|
|||
|
declare y int;
|
|||
|
select sum(col1)
|
|||
|
from mytable
|
|||
|
into y;
|
|||
|
select y*y into ret;
|
|||
|
end //
|
|||
|
delimiter ;
|
|||
|
```
|
|||
|
|
|||
|
```sql
|
|||
|
call myprocedure(@ret);
|
|||
|
select @ret;
|
|||
|
```
|
|||
|
|
|||
|
# <20>α<EFBFBD>
|
|||
|
|
|||
|
<EFBFBD>ڴ洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD>α<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD>α<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD>ʽӦ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>
|
|||
|
|
|||
|
**ʹ<><CAB9><EFBFBD>α<EFBFBD><CEB1><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD>裺**
|
|||
|
|
|||
|
1. <20><><EFBFBD><EFBFBD><EFBFBD>α꣬<CEB1><EAA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ʵ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>
|
|||
|
2. <20><><EFBFBD><EFBFBD><EFBFBD>αꣻ
|
|||
|
3. ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>
|
|||
|
4. <20>ر<EFBFBD><D8B1>αꣻ
|
|||
|
|
|||
|
```sql
|
|||
|
delimiter //
|
|||
|
create procedure myprocedure(out ret int)
|
|||
|
begin
|
|||
|
declare done boolean default 0;
|
|||
|
|
|||
|
declare mycursor cursor for
|
|||
|
select col1 from mytable;
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>continue handler<65><72><EFBFBD><EFBFBD> sqlstate '02000' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4> set done = 1
|
|||
|
declare continue handler for sqlstate '02000' set done = 1;
|
|||
|
|
|||
|
open mycursor;
|
|||
|
|
|||
|
repeat
|
|||
|
fetch mycursor into ret;
|
|||
|
select ret;
|
|||
|
until done end repeat;
|
|||
|
|
|||
|
close mycursor;
|
|||
|
end //
|
|||
|
delimiter ;
|
|||
|
```
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ִ<EFBFBD>У<EFBFBD>DELETE<EFBFBD><EFBFBD>INSERT<EFBFBD><EFBFBD>UPDATE
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>֮ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ִ<EFBFBD>У<EFBFBD>֮ǰִ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> BEFORE <20>ؼ<EFBFBD><D8BC>֣<EFBFBD>֮<EFBFBD><D6AE>ִ<EFBFBD><D6B4>ʹ<EFBFBD><CAB9> AFTER <20>ؼ<EFBFBD><D8BC>֡<EFBFBD>BEFORE <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>;<EFBFBD><CDBE><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
INSERT <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϊ NEW <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
CREATE TRIGGER mytrigger AFTER INSERT ON mytable
|
|||
|
FOR EACH ROW SELECT NEW.col;
|
|||
|
```
|
|||
|
|
|||
|
DELETE <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϊ OLD <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ġ<EFBFBD>
|
|||
|
|
|||
|
UPDATE <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϊ NEW <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϊ OLD <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NEW <20>ǿ<EFBFBD><C7BF>Ա<EFBFBD><D4B1>ĵأ<C4B5><D8A3><EFBFBD> OLD <20><>ֻ<EFBFBD><D6BB><EFBFBD>ġ<EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƹ<EFBFBD><EFBFBD>٣<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ű<EFBFBD><EFBFBD>С<EFBFBD>
|
|||
|
|
|||
|
MySQL <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> CALL <20><><EFBFBD><EFBFBD> <20><>Ҳ<EFBFBD><D2B2><EFBFBD>Dz<EFBFBD><C7B2>ܵ<EFBFBD><DCB5>ô洢<C3B4><E6B4A2><EFBFBD>̡<EFBFBD>
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>transaction<6F><6E>ָһ<D6B8><D2BB> SQL <20><><EFBFBD>䣻
|
|||
|
2. <20><><EFBFBD>ˣ<EFBFBD>rollback<63><6B>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> SQL <20><><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9>̣<EFBFBD>
|
|||
|
3. <20>ύ<EFBFBD><E1BDBB>commit<69><74>ָ<EFBFBD><D6B8>δ<EFBFBD>洢<EFBFBD><E6B4A2> SQL <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
4. <20><><EFBFBD><EFBFBD><EFBFBD>㣨savepoint<6E><74>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ʱռλ<D5BC><CEBB><EFBFBD><EFBFBD>placeholder<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><EFBFBD><EFBFBD> SELECT <20><><EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD> SELECT <20><><EFBFBD><EFBFBD>Ҳû<D2B2><C3BB><EFBFBD>壻Ҳ<E5A3BB><D2B2><EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD> CRETE <20><> DROP <20><><EFBFBD>䡣
|
|||
|
|
|||
|
MySQL <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ύĬ<E1BDBB><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>ύ<EFBFBD><E1BDBB>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>ÿִ<C3BF><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB>ύһ<E1BDBB>Ρ<EFBFBD><CEA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> START TRANSACTION <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>ʽ<EFBFBD>ύ<EFBFBD><E1BDBB><EFBFBD><EFBFBD> COMMIT <20><> ROLLBACK <20><><EFBFBD><EFBFBD>ִ<EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>رգ<D8B1><D5A3><EFBFBD><EFBFBD>»ָ<C2BB><D6B8><EFBFBD>ʽ<EFBFBD>ύ<EFBFBD><E1BDBB>
|
|||
|
|
|||
|
ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> autocommit Ϊ 0 <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>Զ<EFBFBD><D4B6>ύ<EFBFBD><E1BDBB>ֱ<EFBFBD><D6B1> autocommit <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ 1 <20>Ż<EFBFBD><C5BB>ύ<EFBFBD><E1BDBB>autocommit <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣬ROLLBACK <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD> START TRANSACTION <20><><EFBFBD>䴦<EFBFBD><E4B4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˱<EFBFBD><CBB1><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ROLLBACK <20><>ָ<EFBFBD><D6B8><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD>㡣
|
|||
|
|
|||
|
```sql
|
|||
|
START TRANSACTION
|
|||
|
// ...
|
|||
|
SAVEPOINT delete1
|
|||
|
// ...
|
|||
|
ROLLBACK TO delete1
|
|||
|
// ...
|
|||
|
COMMIT
|
|||
|
```
|
|||
|
|
|||
|
# <20>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
1. <20>ַ<EFBFBD><D6B7><EFBFBD>Ϊ<EFBFBD><CEAA>ĸ<EFBFBD>ͷ<EFBFBD><CDB7>ŵļ<C5B5><C4BC>ϣ<EFBFBD>
|
|||
|
2. <20><><EFBFBD><EFBFBD>Ϊij<CEAA><C4B3><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>ʾ<EFBFBD><CABE>
|
|||
|
3. У<><D0A3><EFBFBD>ַ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>αȽϣ<C8BD><CFA3><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>顣
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD>⣬Ҳ<EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
CREATE TABLE mytable
|
|||
|
(col VARCHAR(10) CHARACTER SET latin COLLATE latin1_general_ci )
|
|||
|
DEFAULT CHARACTER SET hebrew COLLATE hebrew_general_ci;
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱָ<EFBFBD><EFBFBD>У<EFBFBD>ԣ<EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SELECT *
|
|||
|
FROM mytable
|
|||
|
ORDER BY col COLLATE latin1_general_ci;
|
|||
|
```
|
|||
|
|
|||
|
# Ȩ<><EFBFBD><DEB9><EFBFBD>
|
|||
|
|
|||
|
MySQL <20><><EFBFBD>˻<EFBFBD><CBBB><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> mysql <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>С<EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
USE mysql;
|
|||
|
SELECT user FROM user;
|
|||
|
```
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
CREATE USER myuser IDENTIFIED BY 'mypassword';
|
|||
|
```
|
|||
|
|
|||
|
<EFBFBD>´<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD>Ȩ<EFBFBD>ޡ<EFBFBD>
|
|||
|
|
|||
|
**<2A><EFBFBD><DEB8>˻<EFBFBD><CBBB><EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
RENAME myuser TO newuser;
|
|||
|
```
|
|||
|
|
|||
|
**ɾ<><C9BE><EFBFBD>˻<EFBFBD>**
|
|||
|
|
|||
|
```sql
|
|||
|
DROP USER myuser;
|
|||
|
```
|
|||
|
|
|||
|
**<2A>鿴Ȩ<E9BFB4><C8A8>**
|
|||
|
|
|||
|
```sql
|
|||
|
SHOW GRANTS FOR myuser;
|
|||
|
```
|
|||
|
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/c73aa08e-a987-43c9-92be-adea4a884c25.png)
|
|||
|
|
|||
|
<EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD> username@host <20><><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>壬username@% ʹ<>õ<EFBFBD><C3B5><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>**
|
|||
|
|
|||
|
```sql
|
|||
|
GRANT SELECT, INSERT ON mydatabase.* TO myuser;
|
|||
|
```
|
|||
|
|
|||
|
**ɾ<><C9BE>Ȩ<EFBFBD><C8A8>**
|
|||
|
|
|||
|
```sql
|
|||
|
REVOKE SELECT, INSERT ON mydatabase.* FROM myuser;
|
|||
|
```
|
|||
|
|
|||
|
GRANT <20><> REVOKE <20><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF>Ʒ<EFBFBD><C6B7><EFBFBD>Ȩ<EFBFBD>ޣ<EFBFBD>
|
|||
|
|
|||
|
- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> GRANT ALL<4C><4C> REVOKE ALL<4C><4C>
|
|||
|
- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ⣬ʹ<E2A3AC><CAB9> ON database.\*<2A><>
|
|||
|
- <20>ض<EFBFBD><D8B6>ı<EFBFBD><C4B1><EFBFBD>ʹ<EFBFBD><CAB9> ON database.table<6C><65>
|
|||
|
- <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD>У<EFBFBD>
|
|||
|
- <20>ض<EFBFBD><D8B6>Ĵ洢<C4B4><E6B4A2><EFBFBD>̡<EFBFBD>
|
|||
|
|
|||
|
**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> Password() <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
```sql
|
|||
|
SET PASSWROD FOR myuser = Password('newpassword');
|
|||
|
```
|
|||
|
|