SELECT * , group_concat( ' ' , concat_ws( ' X ', `sku` , `quantity-purchased` ) , ' ' ),group_concat(' ' , `order_id` , ' ') FROM ( select * from `sale_orders` order by `sku`) T WHERE `shipments` =0 AND `number` =$id GROUP BY `recipient-name` , `ship-address-1` ORDER BY `sku`
以下为查询的结果:
ship name sku-quantity
001-01 wang A0015-00-04-23 X 1
002-02 liu A0041-00-WW-25 X 1 , A0042-00-AC-25 X 1
003-03 li A0041-00-WW-25 X 1 , A0042-00-AC-25 X 1 , A0256-00-O6-34 X 1
004-04 fang A0041-00-WW-25 X 1 ,A0042-00-AC-25 X 1 , A0217-00-SI-33 X 1
请问怎么在此基础上再按sku-quantity字段的SKU个数来排序(就是字符串长度)
------解决方案--------------------
试试 ..... order by count(sku)
------解决方案--------------------
你这个group_concat( ' ' , concat_ws( ' X ', `sku` , `quantity-purchased` ) , ' ' ),group_concat(' ' , `order_id` , ' ')
两个group_concat,
和你的结果
ship name sku-quantity
001-01 wang A0015-00-04-23 X 1
002-02 liu A0041-00-WW-25 X 1 , A0042-00-AC-25 X 1
里怎么对应?
哪个是shu-quantity?