sql为什么select语句无法显示所选的值

时间:2015-11-28 17:23:50

标签: sql

我使用以下声明加入3个表

SELECT 
    c.FIRSTName, c.LASTName, r.feeOwe, r.paidorNotpaid, co.CITY, co.PERIOD, co.YEAR
FROM 
    CLIMBER c 
JOIN 
    REGISTER r ON C.CLIMBERID = R.CLIMBERID
JOIN 
    COMPETITION co ON CO.COMPETITIONID = R.COMPETITIONID;

enter image description here

我得到了我需要的表格但是当我在下面的其他陈述时,它没有显示我想要的结果。任何人都可以启发我。

SELECT 
    c.FIRSTName, c.LASTName, r.feeOwe, r.paidorNotpaid, co.CITY, co.PERIOD, co.YEAR
FROM 
    CLIMBER c 
JOIN 
    REGISTER r ON C.CLIMBERID = R.CLIMBERID
JOIN 
    COMPETITION co ON CO.COMPETITIONID = R.COMPETITIONID;
WHERE
    co.CITY = 'dubai'
    AND paidorNotpaid = null
    AND City = 'Dubai'
    AND Period = 'Summer'
    AND YEAR = 2015;

enter image description here

2 个答案:

答案 0 :(得分:1)

使用:

SELECT c.FIRSTName, c.LASTName, r.feeOwe, r.paidorNotpaid, co.CITY, co.PERIOD,co.YEAR
FROM CLIMBER c 
JOIN REGISTER r 
  ON C.CLIMBERID = R.CLIMBERID
JOIN COMPETITION co 
  ON CO.COMPETITIONID = R.COMPETITIONID
WHERE co.CITY = 'dubai'
  AND paidorNotpaid IS NULL
  AND City = 'Dubai'             -- probably you use the same condtion twice
  AND Period = 'Summer'
  AND YEAR = 2015;

paidorNotpaid = null => NULL这就是为什么你没有得到任何记录。

不要将比较运算符与NULL一起使用。要检查列值是否包含NULL,请使用IS NULL运算符

LiveDemo

答案 1 :(得分:0)

如果您的数据库不区分大小写,请尝试:

SELECT c.FIRSTName, c.LASTName, r.feeOwe, r.paidorNotpaid, co.CITY, co.PERIOD,co.YEAR
FROM CLIMBER c 
JOIN REGISTER r 
  ON C.CLIMBERID = R.CLIMBERID
JOIN COMPETITION co 
  ON CO.COMPETITIONID = R.COMPETITIONID
WHERE co.CITY = 'dubai'
  AND r.paidorNotpaid IS NULL
  AND co.Period = 'Summer'
  AND co.YEAR = 2015;