0
PERSON
DriverID (primary)
DriverName
Address

CAR
RegNO (primary) 
Model 
Year

ACCIDENT
ReportNumber (primary)
AccidentDate
Location

OWNS
DriverID (primary key)  foreign key with PERSON(DriverID)
RegNo (primary Key) foreign key with CAR(RegNo)

PARTICIPATION
DriverID (primary key) foreign key with PERSON (DriverID)
RegNo (primary Key) foreign key with CAR(RegNo)
ReportNumber (primary key) foregin with ACCIDENT(primary)
Damage Amount

查询是 -> 查找涉及属于特定型号的汽车的事故数量

溶胶是

SELECT COUNT (a.ReportNumber)
FROM ACCIDENT a
WHERE
a.ReportNumber in ( SELECT pa.ReportNumber FROM PARTICIPATED pa, CAR c
WHERE pa.RegNo = c.RegNo AND c.Model = 'honda');

我的问题是如何理解涉及 C++ 中嵌套查询的复杂查询你可以使用断点进行调试,但如何在 mySQL 中调试我使用 SQLyog,我知道包括 GROUP 在内的所有基本查询,但是当嵌套查询出现时我无法理解

4

1 回答 1

0

自行运行此查询:

SELECT pa.ReportNumber FROM PARTICIPATED pa, CAR c
WHERE pa.RegNo = c.RegNo AND c.Model = 'honda'

看看reportnumbers并把它们放在你的脑海里。

现在运行这个查询:

SELECT a.ReportNumber FROM ACCIDENT a

因此,第一个查询会为您提供所有报告编号,participated其中包含'honda' car. 第二个查询让你每次reportnumber都在accident.

将它们放在一起,您就可以reportnumber从带有.accidentparticipated'honda'

我希望这能回答你的问题,我不是很清楚你在问什么。

于 2012-12-14T15:03:52.527 回答