PHP/MySQL sort inside GROUP

百般思念 提交于 2019-12-04 12:25:15

SELECT * FROM (SELECT * FROM users_video WHERE location = 'location_1' AND brand IN ('" . implode("','", > $laptop_brands) . '\') GROUP BY brand ) AS P ORDER BY FIELD (brand, "Acer", "Apple", "Dell", "HP-Compaq", "IBM-Lenovo", "Sony", >"Toshiba", "ASUS", "Fujitsu", "Gateway"), official DESC

you can select from your result then order them

I've found the solution. Thx everyone for notes and ideas.

So this is the query I've used to get correct result:

$laptop_brands = array("Acer", "Apple", "Dell", "HP-Compaq", "IBM-Lenovo", "Sony", "Toshiba", "ASUS", "Fujitsu", "Gateway");


$query = "SELECT * FROM (SELECT * FROM users_video WHERE location = 'location_1' AND brand  IN ('" . implode("','", $laptop_brands) . '\') ORDER BY official DESC) as my_table_tmp GROUP BY brand ORDER BY FIELD (brand, "Acer", "Apple", "Dell", "HP-Compaq", "IBM-Lenovo", "Sony", "Toshiba", "ASUS", "Fujitsu", "Gateway")';

Thx all, especially to morteza kavakebi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!