嘗試將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