文件表(req1-7是来自另一个表的要求的id)
| document_id | document_name | document_amount | req_1 | req_2 | req_3 | req_4 | req_5 | req_6 | req_7 |
| 1 | Diploma | 40 | 1 | 3 | 4 | 4 | 6 | 7 | 8 |
需求表
| requirement_id | requirement_name |
| 1 | 1 x 1 picture |
| 2 | 2 x 2 picture |
| 3 | Registration form|
| 4 | Clearance |
| 5 | Medical cert |
| 6 | xray result |
| 7 | excuse letter |
| 8 | affidavit |
| 9 | comsoc clearance |
预期结果类似于文档表,但是需求名称显示为其id的相应值。
我想知道查询这些
的正确语法到目前为止,我的查询是:
SELECT * FROM document_tbl
WHERE requirement1,requirement2,requirement3,requirement4,requirement5,requirement6,requirement7
IN (
SELECT requirement_name FROM requirements_tbl WHERE requirement_id=requirement1,requirement2,requirement3,requirement4,requirement5,requirement6,requirement7 )";
但是我不知何故搞砸了。在此先感谢您的帮助。我很感激。
答案 0 :(得分:1)
中间表(document_requirements)
| document_id | requirement_id |
| 1 | 1 |
| 1 | 3 |
| 1 | 4 |
| 1 | 6 |
| 1 | 6 |
| 1 | 7 |
| 1 | 8 |
查询
SELECT d.document_id,dr.requirement_id,r.requirement_name
FROM documents AS d
JOIN document_requirements AS dr ON (dr.document_id=d.document_id)
JOIN requirements AS r ON (r.requirement_id=dr.requirement_id)
WHERE d.document_id = 1;
答案 1 :(得分:0)
这样的事情:
<form:xxx>
等等。