-5

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 - “缺少表达式” *原因:*操作:

缺少的表达是什么?

4

2 回答 2

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';
于 2013-10-21T09:18:36.680 回答
0

正如人们评论的那样,您错过了FROM您选择的声明。

我还建议不仅在子句中声明所有表FROM并在子句中指定链接WHERE,而是使用和/或s 等join将表一起使用。LEFT JOININNER 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'
于 2013-10-21T09:26:21.537 回答