phpmyadmin 当我在SQL示例中使用〈>/ ORDER BY时,我无法获得正确的输出,

5jdjgkvh  于 2022-11-09  发布在  PHP
关注(0)|答案(1)|浏览(112)

我正在玩我写的SQL示例,当我使用小于、大于或ORDER BY时,我很惊讶我不能得到正确的输出。
例如,select player_name, jersey_number from Players order by 'jersey_number' desc;,它应该给出球员姓名和球衣号码,从球衣号码开始按降序排列。

+--------------------+---------------+
| player_name        | jersey_number |
+--------------------+---------------+
| Karim Benzema      |             9 |
| Kevin De Bruyne    |            17 |
| Kylian Mbappe      |             7 |
| Mohamed Salah      |            11 |
| Christaino Ronaldo |             7 |
| Leonel Messi       |            30 |
| NGolo Kante        |             7 |
| Dusan Vlahovic     |             7 |
| Gabriel Jesus      |             9 |
| Harry Kane         |            10 |
| Lautaro Martinez   |            10 |
| Robert Lewandowski |             9 |
| Hakan Calhanoglu   |            20 |
+--------------------+---------------+

类似地,当我请求只显示此查询中的'player_age' < 30时:select player_name, player_age from Players where 'player_age' < 30;根据以下屏幕截图,输出不正确:

+--------------------+------------+
| player_name        | player_age |
+--------------------+------------+
| Karim Benzema      |         34 |
| Kevin De Bruyne    |         31 |
| Kylian Mbappe      |         23 |
| Mohamed Salah      |         30 |
| Christaino Ronaldo |         37 |
| Leonel Messi       |         34 |
| NGolo Kante        |         31 |
| Dusan Vlahovic     |         22 |
| Gabriel Jesus      |         25 |
| Harry Kane         |         28 |
| Lautaro Martinez   |         24 |
| Robert Lewandowski |         33 |
| Hakan Calhanoglu   |         28 |
+--------------------+------------+

这也是从phpMyAdmin页面:

我通过Mac终端使用MariaBD,我通过phpMyAdmin网站导入了我的.sql文件。
下面是玩家表和价值惯性:

-- Disable Commits & Foreign key Checks
SET FOREIGN_KEY_CHECKS=0;
SET AUTOCOMMIT = 0;

DROP TABLE IF EXISTS Players;

-- Players Table

CREATE TABLE Players (
    player_id int NOT NULL AUTO_INCREMENT,
    player_name varchar(50) NOT NULL,
    player_age int NOT NULL,
    position varchar(50) NOT NULL,
    salary int NOT NULL,
    jersey_number int NOT NULL,
    team_id int NOT NULL,
    PRIMARY KEY (player_id),
    FOREIGN KEY (team_id) REFERENCES Teams(team_id)
)ENGINE = InnoDB;

--
-- Sample Data for `Players` -- Note: Players salary euros per year
--

INSERT INTO Players (player_name, player_age, position, salary, jersey_number, team_id)
VALUES ('Karim Benzema', 34, 'Centre Forward', 24000000, 9, 3),
('Kevin De Bruyne', 31, 'Midfielder', 20800000, 17, 2),
('Kylian Mbappe', 23, 'Center Forward', 90910000, 7, 4),
('Mohamed Salah', 30, 'Right Winger', 18200000, 11, 1),
('Christaino Ronaldo', 37, 'Center Forward', 26800000, 7, 8),
('Leonel Messi', 34, 'Center Forward', 63640000, 30, 14),
('NGolo Kante', 31, 'Midfielder', 15050000, 7, 5),
('Dusan Vlahovic', 22, 'Center Forward', 12960000, 7, 10),
('Gabriel Jesus', 25, 'Center Forward', 13780000, 9, 12),
('Harry Kane', 28, 'Center Forward', 10400000, 10, 6),
('Lautaro Martinez', 24, 'Center Forward', 11110000, 10, 13),
('Robert Lewandowski', 33, 'Center Forward', 23000000, 9, 11),
('Hakan Calhanoglu', 28, 'Center Forward', 9260000, 20, 7);

-- Enable Commits & Foreign Key Checks 
SET FOREIGN_KEY_CHECKS=1;
COMMIT;

注:我删除了几个表,包括:团队、所有者、比赛、团队所有权、奖杯等。我需要帮助来解释为什么order by<>不能输出正确的答案。我在这里做错了什么吗?
提前感谢你的帮助,

w6mmgewl

w6mmgewl1#

从“运动员按球衣号码排序”中选择“运动员姓名”、“球衣号码”;
从年龄〈30的球员中选择球员姓名、球员年龄;
--请勿在Orderby中使用引号--

相关问题