Home > Backend Development > PHP Tutorial > SQL查询排序有关问题

SQL查询排序有关问题

WBOY
Release: 2016-06-13 10:51:39
Original
742 people have browsed it

SQL查询排序问题
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?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template