0
我有一個相當複雜的查詢,它根據子查詢對結果進行排序。這工作正常。查詢如下。從子查詢追加字段
SELECT enrollments.*, users.*
FROM enrollments
INNER JOIN users
ON enrollments.user_id = users.id
WHERE enrollments.preview = FALSE
ORDER BY (
SELECT COUNT(progress_tracker)
FROM progress_tracker
WHERE progress_tracker.enrollment_id = enrollments.id
AND progress_tracker.completed = TRUE
)
這裏我從用戶和註冊表中選擇字段。理想情況下,我希望在sql結果中有更多的字段。此字段表示ORDER BY sql的結果:
SELECT COUNT(progress_tracker)
FROM progress_tracker
WHERE progress_tracker.enrollment_id = enrollments.id
AND progress_tracker.completed = TRUE
是否可以從此查詢創建一個字段並將其附加到每行的結果中?該行的名稱將被適當地稱爲enrollment_progress_tracker_completed_count
。如果是這樣,我該怎麼做?
哇,超爽。謝謝! – jason328