我試圖找到一種方法來創建從數據庫查詢中的結果計算來提供一種相關性。爲每一行選擇計算
這裏是我的查詢的例子:
SELECT d.id, MATCH (r.text) AGAINST('sleet snow rain' IN BOOLEAN MODE) as r_matches, s.total_matches
FROM days d
LEFT JOIN condition_days r
ON (d.id = r.day_id AND MATCH (r.text) AGAINST('sleet snow rain' IN BOOLEAN MODE))
LEFT JOIN (SELECT ss.day_id, COUNT(DISTINCT ss.condition_id) as total_matches FROM conditions ss WHERE ss.condition_id IN (4, 13, 20) GROUP BY ss.day_id) s
ON (s.day_id = d.id)
它返回是這樣的:
+-----+-----------+---------------+
| id | r_matches | total_matches |
+-----+-----------+---------------+
| 540 | 2 | 5 |
+-----+-----------+---------------+
所以我的問題是,我該如何得到2個計算領域的計算(r_matches和TOTAL_MATCHES)? 這是一個例子就是我在尋找:
+-----+-----------+---------------+----------------------------------------------+
| id | r_matches | total_matches | total |
+-----+-----------+---------------+----------------------------------------------+
| 540 | 2 | 3 | 5 (calculation of total_matches + r_matches) |
+-----+-----------+---------------+----------------------------------------------+
那麼,有沒有辦法讓2個計算字段計算總計?