我有一個查詢不能執行,因爲我希望它執行。我幾乎在所有頁面上都使用它來在頁腳中顯示4位隨機輔導員和他們相關的一些數據(他們的名字,他們的頭像以及他們提供的課程數量)。改進此查詢,在Oracle中使用3個連接,也許使用「分區」?
如何在Oracle中提高此查詢的執行速度?我正在看分區和使用分區和其他的東西。我有一個mySQL背景,我可能沒有充分利用Oracle。
我有以下表結構:
tutor_profiles:
id
user_id (FK users)
users:
id
username
avatar_id (FK files)
courses:
id
tutor_id (FK tutor_profiles)
description
...
files
id
file_uri
`
而且我有這個疑問:
SELECT * FROM
(SELECT inner_query.*, rownum rnum
FROM (
SELECT tutor_profiles.id AS "tutor_id"
, tutor_profiles.full_name AS "full_name"
, files.file_uri as "file_uri"
, files.id AS file_id
, tutor_profiles.user_id
, count(distinct courses.id) AS "course_count"
FROM tutor_profiles
LEFT JOIN users ON users.id = tutor_profiles.user_id
LEFT JOIN files ON files.id = users.avatar_id
LEFT JOIN courses ON tutor_profiles.id = courses.tutor_id
GROUP BY tutor_profiles.id, tutor_profiles.full_name, tutor_profiles.user_id, files.file_uri, files.id
ORDER BY dbms_random.VALUE
) inner_query
WHERE rownum <= 4)
該查詢假設要做什麼? – Luke101 2012-03-15 14:30:58
該查詢應該從數據庫中獲得4個隨機輔導者,他們有多少課程,他們的個人資料頭像 – Mythriel 2012-03-15 14:45:06