15 查詢語句

2022-09-16 14:33:12 字數 3346 閱讀 8670

1、命令語法:select 《字段 1,字段 2,..> from

《表名》 where 《表示式》其中,select,

from

,where 是不能隨便改的,是關鍵字,支援大小寫

2、檢視表 test 中所有資料

a.進入指定庫後查詢

mysql>use oldboy

database changed

mysql>show tables;

+------------------+

| tables_in_oldboy |

+------------------+

| student |

| test |

+------------------+

2 rows in set (0.00sec)

mysql> select * from

test;;

+----+-----------+

| id | name |

+----+-----------+

| 1 | oldboy |

| 2 | oldgirl |

| 3 | zhangxuan |

| 4 | engchao |

| 5 | geili |

+----+-----------+

5 rows in set (0.00sec)

error:

no query specified​

mysql> select user,host from

mysql.user;

+-----------+--------------------------+

| user | host |

+-----------+--------------------------+

| root | 127.0.0.1 |

| blog | 172.16.1.% |

| oldgirl | 172.16.1.% |

| wordpress | 172.16.1.% |

| oldgirl | 172.16.1.0/255.255.255.0 |

| oldboy | localhost |

| oldgirl | localhost |

| root | localhost |

+-----------+--------------------------+rows

in set (0.00 sec)​

1、例:檢視表 test 中前兩行資料

執行命令:

mysql> select * from test limit 2;

+----+---------+

| id | name |

+----+---------+

| 1 | oldboy |

| 2 | oldgirl |

+----+---------+

2 rows in set (0.00sec)

2、例:檢視後兩行資料

執行命令:

mysql> select * from test limit 1,2;

+----+-----------+

| id | name |

+----+-----------+

| 2 | oldgirl |

| 3 | zhangxuan |

+----+-----------+

2 rows in set (0.00 sec)​

執行命令:

mysql> select * from test where id=1;

+----+--------+

| id | name |

+----+--------+

| 1 | oldboy |

+----+--------+

1 row in set (0.05sec)

mysql> select * from test where name='

oldboy

'; <-查詢字元中要加引號

+----+--------+

| id | name |

+----+--------+

| 1 | oldboy |

+----+--------+

1 row in set (0.00 sec)​

執行命令:

mysql> select * from test where id>2 and id<5;

+----+-----------+

| id | name |

+----+-----------+

| 3 | zhangxuan |

| 4 | engchao |

+----+-----------+

2 rows in set (0.00 sec)​

正序

mysql> select * from

test order by id asc;

+----+-----------+

| id | name |

+----+-----------+

| 1 | oldboy |

| 2 | oldgirl |

| 3 | zhangxuan |

| 4 | engchao |

| 5 | geili |

+----+-----------+

5 rows in set (0.00sec)

倒序mysql> select * from

test order by id desc;

+----+-----------+

| id | name |

+----+-----------+

| 5 | geili |

| 4 | engchao |

| 3 | zhangxuan |

| 2 | oldgirl |

| 1 | oldboy |

+----+-----------+

5 rows in set (0.00 sec)​

mysql> select * from test where id>2 and id<5 order by id desc into outfile '

/tmp/id.txt';

query ok, 2 rows affected (0.06sec)

mysql> system cat /tmp/id.txt

4engchao

3 zhangxuan

15個很具代表性的MDX查詢語句

15個很具代表性的mdx查詢語句 出處 www.sqlmag.com 原作者russ whitney 02.所有商店中銷售前10名的產品類別有哪些?listing 2 直接利用topcount 函式查詢銷售前10名的產品。這是一種最直接的方法,topcount 函式本身自帶排序 降序 的功能 lis...

語句摘抄 第15周

在乙個科技發達,文化成為一場滑稽戲的時代裡,造就精神枯萎的敵人更可能是乙個滿面笑容的人,而不是那種一眼看上去就讓人心生懷疑和仇恨的人。當膽怯的智慧型還在猶豫的時候,勇敢的無知已經行動了!這句話的隱含之意是,思考和閱讀也許可以讓我們明白一些事理和道理,但不能直接提公升我們的氣節和勇氣,更無法直接激發行...

sql查詢語句 連線語句

若乙個查詢同時涉及兩個以上的表,則稱之為連線查詢。它包括等值連線,非等值連線,自然連線,自身連線,外連線和復合條件連線 表名1.列名1 連線運算子 表名2.列名2 當連線運算子為等號 時,稱為等值連線 使用其它運算子時,稱為非等值連線。若在等值連線中把目標列中重複的屬性列去掉則為自然連線。查詢每個學...