日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql好玩的代码_mysql的order by与where出现的好玩事

發布時間:2023/12/19 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql好玩的代码_mysql的order by与where出现的好玩事 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10001, ‘1953-09-02’, ‘Georgi’, ‘Facello’, ‘M’, ‘1986-06-26’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10002, ‘1964-06-02’, ‘Bezalel’, ‘Simmel’, ‘F’, ‘1985-11-21’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10003, ‘1959-12-03’, ‘Parto’, ‘Bamford’, ‘M’, ‘1986-08-28’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10004, ‘1954-05-01’, ‘Chirstian’, ‘Koblick’, ‘M’, ‘1986-12-01’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10005, ‘1955-01-21’, ‘Kyoichi’, ‘Maliniak’, ‘M’, ‘1989-09-12’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10006, ‘1953-04-20’, ‘Anneke’, ‘Preusig’, ‘F’, ‘1989-06-02’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10007, ‘1957-05-23’, ‘Tzvetan’, ‘Zielinski’, ‘F’, ‘1989-02-10’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10008, ‘1958-02-19’, ‘Saniya’, ‘Kalloufi’, ‘M’, ‘1994-09-15’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (10011, ‘1972-02-29’, ‘He’, ‘Rick’, ‘M’, ‘1991-02-20’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64887, ‘1961-05-15’, ‘Rafols’, ‘Suomi’, ‘F’, ‘1987-06-05’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64888, ‘1962-05-16’, ‘Kristof’, ‘Marchegay’, ‘F’, ‘1988-11-10’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64889, ‘1953-05-08’, ‘Emdad’, ‘Pauthner’, ‘M’, ‘1985-09-07’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64890, ‘1957-08-21’, ‘Leni’, ‘Kilgore’, ‘M’, ‘1995-08-31’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64891, ‘1954-09-27’, ‘Ioana’, ‘Pepe’, ‘F’, ‘1990-08-19’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64892, ‘1964-12-05’, ‘Mayumi’, ‘Tyugu’, ‘F’, ‘1988-03-19’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64893, ‘1953-11-27’, ‘Yoshimitsu’, ‘Billawala’, ‘F’, ‘1986-06-07’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64894, ‘1955-09-19’, ‘Mori’, ‘Weedman’, ‘F’, ‘1999-01-29’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64895, ‘1962-02-24’, ‘Dietrich’, ‘Foote’, ‘M’, ‘1988-08-07’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64896, ‘1960-12-31’, ‘Ingemar’, ‘Schieder’, ‘M’, ‘1995-10-25’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64897, ‘1956-04-24’, ‘Aksel’, ‘Denna’, ‘M’, ‘1986-08-31’);

INSERT INTO?employees?(emp_no,?birth_date,?first_name,?last_name,?gender,?hire_date) VALUES (64898, ‘1961-04-13’, ‘Sudhanshu’, ‘Hutton’, ‘M’, ‘1996-02-09’);

1:實現row_number.

?

2:取前3條:

?

3:對first_name排序取前三條:

?

在沒有排序時得到的事正確的三條數據,但是排序后得到的是21條(全部數據),奇怪。

猜測:

(1)執行了where但是在排序時是將所有的數據都拿出來排序的

(2)沒有執行where,直接排序輸出了。即跳過了where.

看explain:

?

MySQL官方手冊解釋:

Using where

A WHERE clause is used to restrict which rows to match against the next table or send to the client. Unless you specifically intend to fetch or examine all rows from the table, you may have something wrong in your query if the Extra value is not Using where and the table join type is ALL or index.

總結

以上是生活随笔為你收集整理的mysql好玩的代码_mysql的order by与where出现的好玩事的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。