开发者

Nested and complicated select statement

What i want to do here is simple...display an ivestigators ID and him corresponding name... That can be easily done from the users table by selecting based on the user type. However i want to select only some type of investigators. The analogy here is investigators are assigned to an exhibit for them to investigate. One investigator can be assigned to a maximum of 3 cases only. Now during the assigning of investigators, i want to write a select statement that would retrieve only investigatorID's that have been assigned to less than or equal to 2 cases. I have included exhibit and users table that shows sample data below.

Nested and complicated select statement

Nested and complicated select statement

Now i sort of have an idea that i will have to first of all pick out all the investigators by their ID from the users list and then filter them through the exhibit table by dropping those ass开发者_运维问答igned to 3 cases and leaving just those with two cases. then afterwards i use this IDs to select the Investigators name.

the big questions is how do i write the statement??


SELECT InvestigatorID From Cases GROUP BY (InvestigatorId) HAVING COUNT(INvestigatorId) < 3

Is that what you're looking for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜