1

これには答えられないかもしれませんが、クエリが 0 の結果を返す理由を理解しようとしています。

SELECT SQL_CALC_FOUND_ROWS 
  records.instance_id
  ,instances.patient_id
  ,form_1_data.field_1 AS field_0
  ,form_1_data.field_2 AS field_1
  ,records.field_240 AS field_2
  ,**GROUP_CONCAT(events.start_time SEPARATOR '<br />')**  AS field_3 
FROM form_4_data AS records 
LEFT JOIN instances ON instances.id= records.instance_id 
LEFT JOIN events ON records.instance_id = events.instance_id  
LEFT JOIN form_3_data ON records.field_111= form_3_data.instance_id  
LEFT JOIN form_1_data ON form_3_data.field_94= form_1_data.instance_id 
WHERE instances.active=1  
ORDER BY records.instance_id DESC  
LIMIT 25,25

0 の結果を返します。

しかし、

SELECT SQL_CALC_FOUND_ROWS 
  records.instance_id
  ,instances.patient_id
  ,form_1_data.field_1 AS field_0
  ,form_1_data.field_2 AS field_1
  ,records.field_240 AS field_2
  ,**events.start_time AS field_3** 
FROM form_4_data AS records 
LEFT JOIN instances  ON instances.id= records.instance_id 
LEFT JOIN events ON records.instance_id = events.instance_id  
LEFT JOIN form_3_data ON records.field_111= form_3_data.instance_id  
LEFT JOIN form_1_data ON form_3_data.field_94= form_1_data.instance_id 
WHERE instances.active = 1  
ORDER BY records.instance_id DESC  
LIMIT 25,25

戻り値:

instance_id patient_id  field_0  field_1  field_2   field_3
83          40          Jack     Nichols  NULL      2011-04-11 20:00:00
60          8           Olive    Miller   Split     NULL
58          32          Mark     Green    NPSG      2011-03-05 20:00:00
58          32          Mark     Green    NPSG      2011-04-09 20:00:00
58          32          Mark     Green    NPSG      2011-04-02 20:00:00
58          32          Mark     Green    NPSG      2011-04-09 20:00:00
57          32          Mark     Green    MSLT      NULL
56          43          Jeremy   Stevens  NPSG      NULL
31          32          Mark     Green    MWT       2011-04-14 20:00:00
28          29          Jerry    Jones    NULL      2011-04-01 20:00:00
28          29          Jerry    Jones    NULL      2011-04-02 20:00:00
28          29          Jerry    Jones    NULL      2011-03-30 20:00:00
28          29          Jerry    Jones    NULL      2011-04-01 20:00:00
28          29          Jerry    Jones    NULL      2011-04-14 20:00:00
11           8          Olive    Miller   Split     2011-03-11 20:00:00
11           8          Olive    Miller   Split     2011-03-30 20:00:00
11           8          Olive    Miller   Split     2011-03-22 20:00:00
11           8          Olive    Miller   Split     2011-04-06 20:00:00
11           8          Olive    Miller   Split     2011-04-16 20:00:00
11           8          Olive    Miller   Split     2011-03-31 20:00:00
11           8          Olive    Miller   Split     2011-04-02 20:00:00
11           8          Olive    Miller   Split     2011-04-03 20:00:00
9            8          Olive    Miller   NPSG      2011-04-22 20:00:00
9            8          Olive    Miller   NPSG      2011-03-29 20:00:00
9            8          Olive    Miller   NPSG      2011-03-29 20:00:00
4

2 に答える 2

1

group_concatgroup byクエリに句がないため、機能しません。
a を追加するgroup byと動作します。

SELECT SQL_CALC_FOUND_ROWS 
  records.instance_id
  ,instances.patient_id
  ,form_1_data.field_1 AS field_0
  ,form_1_data.field_2 AS field_1
  ,records.field_240 AS field_2
GROUP_CONCAT(events.start_time SEPARATOR '<br />')  AS field_3
FROM form_4_data AS records 
LEFT JOIN instances ON instances.id= records.instance_id 
LEFT JOIN events ON records.instance_id = events.instance_id  
LEFT JOIN form_3_data ON records.field_111= form_3_data.instance_id  
LEFT JOIN form_1_data ON form_3_data.field_94= form_1_data.instance_id 
WHERE instances.active=1  
GROUP BY records.instance_id /*<<-- addition */
ORDER BY records.instance_id DESC  
LIMIT 25,25 
于 2011-04-26T23:25:49.097 に答える
0

日付に新しい行を追加するだけの場合、GROUP_CONCAT は本当に必要なものではありません。これは、GROUP BY と連携して、グループ化されたブロック内の異なる行の文字列を連結する集計関数です。

テーブル週がある場合:

week weekday
1    Monday
1    Tuesday
1    Friday
2    Monday
2    Sunday

クエリ

SELECT week, GROUP_CONCAT( weekday SEPARATOR '<br />' ) as days
FROM weeks
GROUP BY week

あなたに与える:

week days
1    Monday<br />Tuesday<br />Friday
2    Monday<br />Sunday

あなたが探しているのは単純な CONCAT だと思います:

SELECT week, CONCAT( weekday,'<br />' ) as day
FROM weeks

あなたに与える:

week day
1    Monday<br />
1    Tuesday<br />
1    Friday<br />
2    Monday<br />
2    Sunday<br />
于 2011-04-26T23:54:09.110 に答える