我有一個數據庫設置來跟蹤錯誤,使用一個配置文件表來跟蹤誰是誰,以及一個包含所有錯誤信息的錯誤表。我感興趣的每個表中的字段有:MYSQL查詢返回多個用戶輸入參數的行數
概況表:
userid | realname
---------------
1 | Bob
2 | Alice
4 | Carol
...
錯誤表:
id | reporter | short_desc
-----------------------------
1 | 1 | short description 1
2 | 2 | short description 2
3 | 1 | short description 3
4 | 3 | another short description
其中profiles.userid = bugs.reporter,並bugs.id是特定bug的ID
我在PHP中製作一個自動化的報表創建器,最終會以Joomla的Plotalot結束,這意味着它必須是一個查詢。自動報告的用戶可以指定他想要在報告中顯示的人的哪些用戶標識。即:
enter IDS: 1,4
reporter | bugs
--------------
Bob | 2
Carol | 1
該數據庫有超過5,000個錯誤和400個活躍貢獻者。有沒有辦法構建一個查詢來返回格式化的結果,而不使用每個記者的union select?
非常感謝
你說的是COUNT()和左連接?我無法弄清楚UNION與此有何關係: - ? –
UNION SELECT將允許我構建一個基於每個id在for循環在php中的查詢,即 選擇實名,COUNT(*)從配置文件INNER JOIN錯誤ON profiles.userid = bugs.reporter WHERE記者= 1 UNION SELECT .... WHERE記者= 4; – Robert