> ID ProductID OptionName OptionValue SKU
>
> 1 709 Title Como test
> 2 709 Color Cobalt test
> 3 709 Color Crimson RNA.331.02.MM1K
> 4 709 Title Como G2 RNA.331.02.MM1K
> 7 709 Color another color test ipn
> 8 709 Title another title test ipn
值從上面的表格,我想下面的如何提取從SQL表
Select distinct OptionName from myTable where ProductID = 709 group by OptionValue
但SQL Server是給在GROUP BY子句中的錯誤和不知道怎樣纔可以有各種不同的價值觀分組到不同的OptionName?
或者我不能?
我想要的結果如下
[0] => array
[Color] => array
[0] => Cobalt test
[1] => Crimson
[2] => another color
[Title] => array
[0] => Como test
[1] => Como G2
[2] => another title
的SQL語義錯誤的,但我不明白你想要什麼。您選擇一列(不使用組功能),而選擇另一列。這在語義上是不正確的。它由(不帶下劃線)組合而成。 – 2011-05-20 12:14:13
SQL無法返回嵌套數組。你將不得不改變客戶端上的扁平行集。 – Andomar 2011-05-20 13:15:47