-1

我的表由 5 个字段组成:

Submission ValueId  1 2 3 4 5
FormId  1 2 3 4 5
SubmissionId  22 or 23 or 24 
FieldName  fullname,Date,ville,
FieldValue 1 Paul  01/10/2013 Bern

我想要的表:

SELECT FormId, SubmissionId, FieldValue FROM qesnd_rsform_submission_values WHERE      FieldValue = Bern AND FormID='1' ORDER BY SubmissionId ASC"

使用 formid:1
使用 FieldValue:Paul
使用 FieldValue: 2013 年 1 月 10 日
使用 FielValue:伯尔尼

我的问题如何通过多项选择使我的请求 phpMyAdmin?

4

1 回答 1

0

看起来您的数据有点过度规范化,每个字段都有单独的行。我认为访问此数据的最佳方式是通过聚合,假设字段名称对于任何形式都不重复:

select formid, submissionId,
       max(case when fieldName = 'FullName' then fieldvalue end) as FullName,
       max(case when fieldName = 'Date' then fieldvalue end) as DateStr,
       max(case when fieldName = 'ville' then fieldValue end) as Ville
from t
where formid = 1
group by SubmissionId

如果要选择过滤器上的信息,请尝试:

select *
from (select formid, submissionId,
             max(case when fieldName = 'FullName' then fieldvalue end) as FullName,
             max(case when fieldName = 'Date' then fieldvalue end) as DateStr,
             max(case when fieldName = 'ville' then fieldValue end) as Ville
      from t
      group by SubmissionId
     ) t
 where formid = 1 and FullName = 'Paul' and DateStr = '01/10/2013' and Ville = 'Bern'
于 2013-02-03T16:12:25.890 回答