データベースに 3 つのテーブルがあります
従業員表
- 従業員 ID (PK)
- 苗字
質問表
- Qid (PK)
- 質問
アンケート
- アンケート ID (PK)
- QID (外部キー)
- 従業員 ID (外部キー)
- 応答
- 詳細
これは私が自分で書いた SQL クエリですが、必要のない出力を生成しています。
Select q.qid,e.employeeId, q.Question, eq.response
from employee e
cross join Question q
left outer join employeequestionnaire eq on q.Qid= eq.Qid
where e.employeeId = 1
これが出力です
Qid EmployeeId Question Response
"1" "1" "Question1" "0"
"1" "1" "Question1" "1"
"2" "1" "Question2" "1"
"2" "1" "Question2" "0"
"3" "1" "Question3" "1"
"4" "1" "Question4" NULL
しかし、私はこの種の出力が必要です
Qid EmployeeId Question Response
"1" "1" "Question1" "0"
"2" "1" "Question2" "1"
"3" "1" "Question3" "1"
"4" "1" "Question4" NULL
私は SQL の初心者です。サンプル クエリで申し訳ありません。