+--------+-------------+-----+
| req_id | req_name | ... |
+--------+-------------+-----+
| 1 | testrequest | ... |
+--------+-------------+-----+
とMySQLのテーブルとそのような要求に票を持つテーブルがあります。
+--------+-----------+----------+
| req_id | vote_name | approved |
+--------+-----------+----------+
| 1 | User1 | 1 |
| 1 | User2 | 1 |
| 1 | User3 | 1 |
| 1 | User4 | 0 |
| 1 | User5 | 0 |
+--------+-----------+----------+
私が欲しいビューの種類:
+--------+-------------+----------+---------------------+
| req_id | req_name | approved | by |
+--------+-------------+----------+---------------------+
| 1 | testrequest | YES | User1, User2, User3 |
| 1 | testrequest | NO | User4, User5 |
+--------+-------------+----------+---------------------+
私が使用したクエリ:
+--------+-------------+---------------------+--------------+
| req_id | req_name | approved_by | rejected_by |
+--------+-------------+---------------------+--------------+
| 1 | testrequest | User1, User2, User3 | User4, User5 |
+--------+-------------+---------------------+--------------+
はこれまでのところ、しかし、私はこれを実現することができました
SELECT requests.req_id, req_name, CASE
WHEN approved THEN 'YES'
ELSE 'NO'
END AS approved, GROUP_CONCAT(vote_name ORDER BY vote_name ASC SEPARATOR ', ') AS by
FROM requests
LEFT JOIN votes ON requests.req_id = votes.req_id
GROUP BY requests.req_id, approved
ORDER BY requests.req_id DESC;
私の質問は、どうすれば2つのgroup_c同じ行の別の値でのoncats?
ありがとうございます!
'group_concat' – safarov