MySQL SELECT WHERE PERSON_NAME =函数不起作用

时间:2019-02-07 05:25:12

标签: mysql sql

因此,我正在尝试SQL并逐步进行自我教学,由于某种原因,此方法无法正常工作。我得到的只是表内容名称,将弹出一个网格,显示“ PERSON_NAME PERSON_SURNAME BIRTH_PLACE BIRTH_DATE YEARLY_WAGE PERSON_AGE”在MySQL的网格框中,但没有我插入的值。这是代码

CREATE TABLE PEOPLES (
PERSON_NAME VARCHAR(50) NOT NULL,
PERSON_SURNAME VARCHAR(50) NOT NULL,
BIRTH_PLACE VARCHAR(50) NOT NULL,
BIRTH_DATE date NOT NULL,
YEARLY_WAGE INT (50) NOT NULL,
PERSON_AGE INT (50) NOT NULL
);
INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE, YEARLY_WAGE, PERSON_AGE)
VALUES ("Trollfire", "Lolmay", "Montenegro", 29042000, 600000, 19);
INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE, YEARLY_WAGE, PERSON_AGE)
VALUES ("Thomas", "Trainson", "Albania", 17091964, 100000, 60);
INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE, YEARLY_WAGE, PERSON_AGE)
VALUES ("Stefan", "Savic", "Serbia", 19021972, 234567, 25);
INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE, YEARLY_WAGE, PERSON_AGE)
VALUES ("Milo", "Djukanovic", "Croatia", 999999, 01011922, 70);
INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE, YEARLY_WAGE, PERSON_AGE)
VALUES ("Vladimir", "Putin", "Russia", 444444, 11121933, 62);
INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE, YEARLY_WAGE, PERSON_AGE)
VALUES ("Cristiano", "Ronaldo", "France", 777777, 03031993, 34);
INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE, YEARLY_WAGE, PERSON_AGE)
VALUES ("Lionel", "Messi", "Spain", 101010, 10101910, 40);
SELECT * FROM PEOPLES
WHERE PERSON_NAME = "Vladimir";

2 个答案:

答案 0 :(得分:2)

您的日期文字不正确,可能是插入语句中的其他问题。这是具有有效语法的版本:

INSERT INTO PEOPLES (PERSON_NAME, PERSON_SURNAME, BIRTH_PLACE, BIRTH_DATE,
    YEARLY_WAGE, PERSON_AGE)
VALUES
    ('Trollfire', 'Lolmay', 'Montenegro', '2000-04-29', 600000, 19);

Demo

请注意,字符串文字通常应使用单引号而不是双引号。另外,see the MySQL documentation表示有效的日期文字格式。

答案 1 :(得分:2)

问题在于您的表中只有一行。

mysql> select * from peoples;
+-------------+----------------+-------------+------------+-------------+------------+
| PERSON_NAME | PERSON_SURNAME | BIRTH_PLACE | BIRTH_DATE | YEARLY_WAGE | PERSON_AGE |
+-------------+----------------+-------------+------------+-------------+------------+
| Lionel      | Messi          | Spain       | 2010-10-10 |    10101910 |         40 |
+-------------+----------------+-------------+------------+-------------+------------+

这是因为大多数插入操作失败。

ERROR 1292 (22007): Incorrect date value: '29042000' for column 'BIRTH_DATE' at row 1

我认为是DDMMYYYY。日期通常是YYYYMMDD,而不是数字。一次插入恰好有一个有效日期。