以下是我的表格:
CREATE TABLE Ships (name VARCHAR(20) PRIMARY KEY, launched DATE);
CREATE TABLE Battles (name VARCHAR(20) PRIMARY KEY, battledate DATE);
现在,当我尝试这样做时:
SELECT launched FROM Ships WHERE name='ship_one' > (SELECT battledate FROM Battles WHERE name='battle_one');
它触发了这个:
ERROR: invalid input syntax for type date: "ship_one"
但名称应该是字符串,而不是日期。
SELECT launched FROM Ships WHERE name='ship_one';
工作正常
SELECT now() > (SELECT battledate FROM Battles WHERE name='battle_one');
也可以正常工作(输出f表示错误)
任何人都可以找出问题所在吗?
当我尝试
时(SELECT launched FROM Ships WHERE name='ship_one') > (SELECT battledate FROM Battles WHERE name='battle_one');
它返回
syntax error at or near ">"
答案 0 :(得分:1)
你是混合条件 这是一个条件
SELECT launched FROM Ships WHERE name='ship_one'
这似乎是另一个条件。
> (SELECT battledate FROM Battles WHERE name='battle_one');
您正在尝试使用日期混合和布尔条件(name ='ship_one',它返回一个布尔值)。
SELECT launched FROM Ships WHERE name='ship_one' **AND** somedate > (SELECT battledate FROM Battles WHERE name='battle_one');
答案 1 :(得分:1)
搞定了
select (select launched from ships where name = 'ship_one') > (select battledate from battles where name = 'battle_one');
答案 2 :(得分:-1)
WHERE name='ship_one' > (SELECT battledate FROM Battles WHERE name='battle_one');
缩减为:
(boolean) > battledate (error)
可能想要:
where name='ship one' and something??? > battledate