0

我有一个查询返回一个包含 25 位医生的列表,这些医生需要在一列中反映他们上传的文件 (cloud_uploads)。问题是,我不想限制列出的文件数量,但限制似乎也适用于文件。我见过的关于 SO 的其他类似问题有相反的问题——他们想限制文件而不限制返回的总行数。我的医生上传了超过 25 个文件,但该列表仅显示前 25 个文件,而不是所有文件。

因为这是一个以编程方式生成的查询,所以我不能将它分成多个查询。它必须是一个。因此,如果答案是无法完成,我可以接受。

这是当前的查询:

SELECT SQL_CALC_FOUND_ROWS records.instance_id,
        instances.patient_id,
        TRIM(form_1_data.field_2) AS field_0,
        TRIM(form_1_data.field_1) AS field_1,
        TRIM(form_1_data.field_87) AS field_2,
        GROUP_CONCAT(DISTINCT CONCAT (
                        extensible_8_data.field_953,
                        '|||',
                        cloud_uploads.NAME
                        ) SEPARATOR '<br />') AS field_3
FROM form_6_data AS records
LEFT JOIN instances
        ON instances.id = records.instance_id
LEFT JOIN extensible_8_data
        ON records.instance_id = extensible_8_data.instance_id
LEFT JOIN cloud_uploads
        ON extensible_8_data.field_953 = cloud_uploads.id
LEFT JOIN form_1_data
        ON records.field_89 = form_1_data.instance_id
WHERE instances.form_id = 6
        AND instances.active = 1
        AND (
                cloud_uploads.active = 1
                OR cloud_uploads.active IS NULL
                )
GROUP BY records.instance_id
ORDER BY records.instance_id DESC LIMIT 0, 25
4

1 回答 1

1

加入一个子查询,选择 25 位感兴趣的医生及其文件:

SELECT SQL_CALC_FOUND_ROWS records.instance_id,
        instances.patient_id,
        TRIM(form_1_data.field_2)  AS field_0,
        TRIM(form_1_data.field_1)  AS field_1,
        TRIM(form_1_data.field_87) AS field_2,
        GROUP_CONCAT(DISTINCT CONCAT (
                        extensible_8_data.field_953,
                        '|||',
                        cloud_uploads.NAME
                        ) SEPARATOR '<br />') AS field_3
FROM (SELECT * FROM form_6_data ORDER BY instance_id DESC LIMIT 25) AS records
LEFT JOIN instances
        ON instances.id = records.instance_id
LEFT JOIN extensible_8_data
        ON records.instance_id = extensible_8_data.instance_id
LEFT JOIN cloud_uploads
        ON extensible_8_data.field_953 = cloud_uploads.id
LEFT JOIN form_1_data
        ON records.field_89 = form_1_data.instance_id
WHERE instances.form_id = 6
        AND instances.active = 1
        AND (
                cloud_uploads.active = 1
                OR cloud_uploads.active IS NULL
                )
GROUP BY records.instance_id
ORDER BY records.instance_id
于 2012-10-08T16:17:44.243 回答