尝试将JOIN
语句用于从多个表中选择值时,我得到ORA-00932: inconsistent datatypes: expected - got BLOB
。以下是我的Oracle SQL代码:ORA-00932:不一致的数据类型:预计 - 在尝试连接不同的表时遇到BLOB
SELECT
MAX(questions.id),
MAX(questions.question),
MAX(questions.author),
MAX(questions.datetime),
MAX(answers.answer),
MAX(answers.usr),
MAX(answers.ansdatetime)
FROM
questions
LEFT JOIN
answers ON
questions.id = answers.question
LEFT JOIN
questions_tags ON
questions.id = questions_tags.question_id
WHERE
questions_tags.tag_id IN (1,2,3,4,5,6)
GROUP BY
questions.id, answers.id
ORDER BY
questions.datetime DESC
以下是三个表的表结构:
questions
:
id int not null,
question varchar(999),
details varchar(1000) not null,
author int not null,
datetime varchar(999)
answers
id int not null, primary key(id),
question int not null,
answer blob not null,
usr int not null,
ansdatetime int not null
questions_tags
id INT NOT NULL,
question_id INT NOT NULL,
tag_id INT NOT NULL,
PRIMARY KEY(id)
这里有什么问题?
我的猜测是MAX未定义为BLOB值,所以'MAX(answers.answer)'失败。您可能实际上需要一个子查询,而不是单独采用每列的MAX。或者将所有选定的列放在GROUP BY中,而不仅仅是ID。 – IMSoP 2014-08-27 23:05:10
'answers.answer'是一个'blob'。你不能在'blob'上做'MAX'。但是你似乎不太可能想在每个列上做一个'MAX'。这通常会将数据组合在一起用于多行。你真的想为特定问题得到最近的答案吗? – 2014-08-27 23:05:46
@JustinCave是的,如果答案存在,我需要得到最近回答的问题的答案。 – DemCodeLines 2014-08-27 23:18:53