我有一个名为table_B的表,其样本集如下:

+-serviceID-+-priceID-+-processOrder-+
|    001    |   003   |      03      |
+-----------+---------+--------------+
|    001    |   024   |      02      |
+-----------+---------+--------------+
|    001    |   001   |      01      |
+-----------+---------+--------------+


这是我的查询语句:

$query_string = '
  SELECT services.*, GROUP_CONCAT(prices.priceID) AS priceID
  FROM table_A AS services
  INNER JOIN table_B AS prices ON services.serviceID = prices.serviceID
  WHERE services.serviceID = "' . $serviceID . '"
  GROUP BY prices.serviceID
  LIMIT 1
';
$result = mysqli_query($link, $query_string);


$ row ['priceID']的结果为string(11) "001,003,024"

如何根据processOrder列在$ row ['priceID']中排序结果字符串?

我试图将$ row ['priceID']作为string(11) "001,024,003"返回

最佳答案

看看GROUP_CONCAT syntax

GROUP_CONCAT([DISTINCT] expr [,expr ...]
         [ORDER BY {unsigned_integer | col_name | expr}
             [ASC | DESC] [,col_name ...]]
         [SEPARATOR str_val])


您可以在括号内设置顺序。

09-26 08:21