1

我正在使用此代码从我创建的表中检索数据。

SELECT id,shirt_name,boys FROM shirts WHERE boys IS NOT NULL

它不只是选择男孩列输入的行,而是选择所有这些行。这是我创建表格的方式

CREATE TABLE shirts (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
    shirt_name VARCHAR(20) NOT NULL,
    men VARCHAR(10) NULL,
    women VARCHAR(10) NULL,
    boys VARCHAR(10) NULL,
    girls VARCHAR(10) NULL,
    babies VARCHAR(10) NULL,
)ENGINE=INNODB;

INSERT INTO shirts(shirt_name,men,women,boys,girls,babies) VALUES
    ('Crewneck Tee','me_crn','wo_crn','bo_crn','gi_crn','ba_crn'),
    ('V-Neck Tee','me_vnc','wo_vnc','','',''),
    ('Scoop Neck Tee','','wo_sco','','',''),
    ('Raglan Tee','me_rag','wo_rag','bo_rag','gi_rag',''),
    ('Ringer Tee','me_rin','wo_rin','bo_rin','gi_rin',''),
    ('Cap Sleeve Tee','','wo_cap','','gi_cap',''),
    ('Tank Top','me_tan','wo_tan','bo_tan','gi_tan',''),
    ('Spaghetti Strap','','wo_spa','','',''),
    ('Hoodie','me_hod','wo_hod','bo_hod','gi_hod','ba_hod');

我做错什么了?

4

2 回答 2

4

您没有NULLboys列中插入任何记录。只记录空字符串。并且空字符串 ( '') 与 不同NULL,所以它匹配IS NOT NULL

于 2012-12-30T00:26:00.727 回答
1
SELECT id,shirt_name,boys FROM shirts WHERE boys != ''

是您需要使用此数据的内容吗

于 2012-12-30T00:31:50.037 回答