我有以下 2 个表 tableA a (id, name, surname, program, date) tableB b (id,aid, name, surname, extracard) with tableA.id = tableB.aid (1 to n 关系)
Sample data for tableA:
| ID | NAME | SURNAME | PROGRAM | DATE | EXPIRES |
----------------------------------------------------------
| 1 | TOM | JONES | 1,2,3 | 12/8/2012 | 12/8/2013 |
| 2 | JAMIE | OLIVER | 4,5,6 | 15/8/2012 | 15/8/2013 |
Sample data for tableB:
| ID | AID | NAME | SURNAME | CARD |
-------------------------------------
| 1 | 1 | ANNE | JONES | 1 |
| 2 | 1 | JACK | BOWER | 0 |
| 3 | 2 | KATE | PERRY | 1 |
| 4 | 2 | JOHN | DOE | 0 |
| 5 | 2 | HARRY | POTTER | 0 |
在结果中,tableB 的每个成员都应该具有来自 tableA 的所有值(程序、日期、过期等...),并且在同一列中只显示来自 tableB 的名称、姓氏(coalesce??)。此外,我需要在 (%id1 和 %id2) 之间为 a.id 使用 between 子句,还需要使用 WHERE 语句来选择 tableB.card=1 的行
| a.ID | NAME | SURNAME | PROGRAM | DATE | EXPIRES |
------------------------------------------------------------
| 1 | TOM | JONES | 1,2,3 | 12/8/2012 | 12/8/2013 |
| 1 | ANNE | JONES | 1,2,3 | 12/8/2012 | 12/8/2013 |
| 2 | JAMIE | OLIVER | 4,5,6 | 15/8/2012 | 15/8/2013 |
| 2 | KATE | PERRY | 4,5,6 | 15/8/2012 | 15/8/2013 |