0

今日 10 人以上の患者を受け入れた病棟ごとに、病棟名、病棟の種類、各病棟のベッド数をリストします。

次のスキーマを指定します。

Patient(PatNo, patName, patAddress, DOB)
Ward (wardNo, wardName, wardType, noOfBeds)
Contains (PatNo, WardNo, admissionDate)

ここに私のSQLがあります:

select PatNo, wardNo, wardName, wardType, noOfBeds
  from Ward w , Contains c
 where w.wardNo = c.WardNo 
   and count(c.patNo) > 10 
   and c.admissionDate = getDate();

関係代数で集計を使用する方法がわかりません。

4

2 に答える 2

1

現在の日付の MySQL 関数はnow()ではなくgetdate(). これを試して:

select PatNo, wardNo, wardName, wardType, noOfBeds
  from Ward w join
       Contains c
       on w.wardNo = c.WardNo 
 where c.admissionDate = date(now())
 group by c.patno
 having count(c.patNo) > 10 

Your query needs a group by clause for the aggregation. The condition on count needs to be in a having clause rather than in a where clause (which is used before aggregation rather than after).

I changed the query to use standard joins.

于 2013-04-20T14:44:30.647 に答える