我有以下查询:
SELECT
count(form_rows.field_name),
form_rows.field_name,
sum(form_rows.field_value) as sales,
form_Submissions.id as fsId
FROM form_submissions
LEFT JOIN form_rows on form_Submissions.id = form_rows.form_submission_id
WHERE form_submissions.organization_id = 10
GROUP BY form_rows.field_name
问题:基于SUM
COUNT
和field_name
是否有办法
澄清:
说我有一个数组:["ssn", "price"]
我想仅将sales
与field_names
存在于给定数组中
答案 0 :(得分:0)
这不是这样做的吗?
SELECT
count(form_rows.field_name),
form_rows.field_name,
sum(form_rows.field_value) as sales,
form_Submissions.id as fsId
FROM form_submissions
LEFT JOIN form_rows on form_Submissions.id = form_rows.form_submission_id
WHERE form_submissions.organization_id = 10
AND form_rows.field_names in ('ssn','price')
GROUP BY form_rows.field_name