我想通过计算产品表中的course_id
找出最多提供的课程标题。
课程:
+-----------+--------------+-----------------+-------------+
| course_id | course_title | course_duration | course_cost |
+-----------+--------------+-----------------+-------------+
发售:
+-------------+-----------+-------------------+-----------------+-------------------+
| offering_id | course_id | course_start_date | course_location | course_instructor |
+-------------+-----------+-------------------+-----------------+-------------------+
我尝试了以下查询,但我不知道为什么,但收到错误消息:
SELECT COURSE.COURSE_TITLE,
OFFERING.OFFERING_ID,
OFFERING.COURSE_ID
COUNT (OFFERING.COURSE_ID) as Mostly_Offered_Course
FROM OFFERING
INNER JOIN COURSE
ON COURSE.COURSE_ID = OFFERING.COURSE_ID
我是oracle的新手,SQL可以指出我犯了错误的地方,谢谢。
答案 0 :(得分:0)
SELECT course_title FROM Course WHERE course_id =
(
SELECT course_id FROM
(
SELECT course_id, COUNT(course_id) AS course FROM Offering
GROUP BY course_id
ORDER BY course DESC
) AS a LIMIT 1
)
这将获得最常用的标题。测试了mysql。在MSSQL上,只需在第二个选择中将“LIMIT 1”和Modified“course_id”删除为“First(course_id)”。