3

我有一个案例,我必须按品牌对表中的结果进行分组,然后按其他列排序。

我从数组中获取我的品牌。问题是当我按品牌分组时,这个组是按 ID 排序的(组内)。有没有办法在组内排序(排序)?

这是我的数组和 mysql 查询。

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

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

2 回答 2

0

我找到了解决方案。谢谢大家的笔记和想法。

所以这是我用来获得正确结果的查询:

$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")';

谢谢大家,尤其是 morteza kavakebi

于 2012-08-06T01:10:49.453 回答
0

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”),官方 DESC

你可以从你的结果中选择然后订购它们

于 2012-08-05T12:14:12.097 回答