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出现的好玩事的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 食之契约落樱缤纷活动怎么玩?水信玄饼皮肤
- 下一篇: 合肥公积金怎么提取出来 如何提取合肥公积