Qns:项目描述和任何名为Jessie Stange的患者的治疗日期(即GivenName是Jessie& FamilyName是Stange)
我写的:
SELECT DISTINCT
Description,
Date as treatmentDate
WHERE doothey.Patient P,
doothey.Account A,
doothey.AccountLine AL,
doothey.Item.I AND
P.PatientID = A.PatientID AND
A.AccountNo = AL.AccountNo AND
AL.ItemNo = I.ItemNo AND
(p.FamilyName = 'Stange' AND p.GivenName = 'Jessie');
错误:
命令行错误:1列:30错误报告:SQL错误:ORA-00936:缺少表达式00936. 00000 - “缺少表达式”*原因:*操作:
缺少什么表达?
答案 0 :(得分:4)
正确的语法如下。
SELECT DISTINCT Description, Date as treatmentDate
FROM
doothey.Patient P, doothey.Account A, doothey.AccountLine AL, doothey.Item I
WHERE P.PatientID = A.PatientID AND A.AccountNo = AL.AccountNo
AND AL.ItemNo = I.ItemNo
AND (p.FamilyName = 'Stange' AND p.GivenName = 'Jessie');
虽然上面的查询可行,但推荐的方法是使用ANSI SQL JOIN语法
SELECT DISTINCT Description, Date as treatmentDate
FROM doothey.Patient P
INNER JOIN doothey.Account A
ON P.PatientID = A.PatientID
INNER JOIN doothey.AccountLine AL
ON A.AccountNo = AL.AccountNo
INNER JOIN doothey.Item I
ON AL.ItemNo = I.ItemNo
WHERE
p.FamilyName = 'Stange' AND p.GivenName = 'Jessie';
答案 1 :(得分:0)
正如人们所评论的那样,您错过了选择中的FROM
声明。
我还建议不只是在FROM
中声明所有表格并在WHERE
子句中指定链接,而是使用join
表格一起使用LEFT JOIN
和/或INNER JOIN
等等。
以下是我认为应该涵盖我上面试图解释的问题。
SELECT DISTINCT
Description,
Date as treatmentDate
FROM
doothey.Patient P
INNER JOIN
doothey.Account A
ON
P.PatientID = A.PatientID
INNER JOIN
doothey.AccountLine AL
ON
A.AccountNo = AL.AccountNo
INNER JOIN
doothey.Item.I
ON
AL.ItemNo = I.ItemNo
WHERE
p.FamilyName = 'Stange'
AND
p.GivenName = 'Jessie'