1

我正在尝试无限次加入自己的表。列是:

+----------+---------+         +--------+--------+--------+---+-----+-----+-----+
| ClientID |  Data   |         | Client |  Data  | Client | * | Cli |  *  | ... |
+----------+---------+         +--------+--------+--------+---+-----+-----+-----+
|  7       | *data*  |         |    7   | *data* |    8   | * |  9  |  *  |     |
|  7       | *data*  |         |    7   | *data* |    8   | * |  9  |  *  |     |
|  8       | *data*  |    ->   |    7   | *data* |    8   | * |  9  |  *  |     |
|  9       | *data*  |         |    7   | *data* |   ...  | * | ... |     |     |
|  ...     |  ...    |         |   ...  |   ...  |        | * |     |     |     |
+--------------------+         +--------+--------+--------+--+-----+------+-----+

我不知道不同客户的数量,我需要完全加入的表。我尽量不使用动态 SQL,我怀疑这是最简单的方法。任何帮助,将不胜感激。

4

1 回答 1

0

也许

select distinct clientid, 
stuff((select ','+DATA 'data()'
from [table] t1
where t1.clientid=t2.clientid
for xml path('')),1,1,'')
from [table] t2
于 2013-03-20T19:02:05.837 回答