我有一个表“产品”,它包含如下的值。
column-a column-b column-c column-d ....
1023 57 value1 value2 ....
1024 58 value3 value4 ....
1025 58 value5 value6 ....
1026 57 value7 value8 ....
1027 59 value9 value10 ....
1028 60 value11 value12 ....
1029 59 value13 value14 ....
从这张表中我想按列-b显示结果如下。
阵列
(
[0] => stdClass Object
(
[column-a] => 1023
[column-b] => 57
[column-c] => value1
[column-d] => value2
.
.
.
)
[1] => stdClass Object
(
[column-a] => 1024
[column-b] => 58
[column-c] => value3
[column-d] => value4
.
.
.
)
[2] => stdClass Object
(
[column-a] => 1027
[column-b] => 59
[column-c] => value9
[column-d] => value10
.
.
.
)
[3] => stdClass Object
(
[column-a] => 1028
[column-b] => 60
[column-c] => value11
[column-d] => value12
.
.
.
)
[4] => stdClass Object
(
[column-a] => 1026
[column-b] => 57
[column-c] => value7
[column-d] => value8
.
.
.
)
[5] => stdClass Object
(
[column-a] => 1025
[column-b] => 58
[column-c] => value5
[column-d] => value6
.
.
.
)
[6] => stdClass Object
(
[column-a] => 1029
[column-b] => 59
[column-c] => value13
[column-d] => value14
.
.
.
)
)
如何按列-b从表组中选择所有表值。
我试过如下,但它的显示值只有列-b
的一次SELECT * FROM products GROUP BY column-b;
有人帮助检索所有相同的数据。提前谢谢!
答案 0 :(得分:0)
您可以按如下方式使用查询:
SELECT column-a,column-b,GROUP_CONCAT(column-c SEPARATOR ' , '),GROUP_CONCAT(column-d SEPARATOR ' , ') FROM products GROUP BY column-b
它将返回具有不同column-b值的记录数组,其中包含column-c和column-d的多个值