我浪费了整整 2 天的时间来尝试解决这个问题,现在我疯了,我需要紧急帮助,问题是,我必须要桌子
表:销售额,SalesId为primary key
---------------------------------------------------
SalesId | SalesDate | Customer| Discount | Remarks
---------------------------------------------------
1 | 01/01/2012| John | 15 | NULL
2 | 01/01/2012| Peter | 25 | NULL
3 | 01/01/2012| Micheal | 35 | NULL
表:SalesBody,SerialNo是primary key
,SalesId是foreign key
---------------------------------------------------
SerialNo | SalesId | Product | Quantity | Rate
---------------------------------------------------
10 | 1 | Pencil | 18 | 20
11 | 1 | pen | 200 | 60
12 | 1 | Rubber | 150 | 10
13 | 1 | Paper | 500 | 2
14 | 2 | Mouse | 15 | 190
15 | 2 | KeyBoard | 10 | 600
16 | 2 | Monitor | 5 | 2000
17 | 3 | Mobile | 2 | 15000
现在我想做一个查询,可以得到如下结果
----------------------------------------------------------------------------
SalesId | SalesDate | Details | Amount
----------------------------------------------------------------------------
1 | 01/01/2012 | Sold: Pencil x 18 @ 20, Pen x 200 @ 60| xxxxxxx
| | Rubber x 150 @ 10, Paper x 500 @ 2 |
2 | 01/01/2012 | Sold: Mouse x 15 @ 190, Keyboard x 10 |
| | @ 600, Monitor x 5 @ 2000 | xxxxxxx
3 | 01/01/2012 | Sold: Mobile x 2 @ 15000 | xxxxxxx
我尝试了不同的技术,例如。合并,东西,用于 XML PATH('')
我无法连接详细信息字符串。