php - cakephp pagination with complex query -
i have database structure given below
id | title | brand | ---+---------+-------+ 1 |product1 | lg | 2 |pruduct2 | lg | 3 |pruduct3 | lg | 4 |pruduct4 | lg | 5 |pruduct5 | lg | 6 |pruduct6 |samsung| 7 |pruduct7 |samsung| 8 |pruduct8 |samsung| 9 |pruduct9 |samsung| 10 |pruduct10|samsung| 11 |pruduct11| sony | 12 |pruduct12| sony | 13 |pruduct13| sony | 14 |pruduct14| sony | 15 |pruduct15| sony |
we need query can mix results brands
output should like
id | title | brand | ---+---------+-------+ 1 |product1 | lg | 6 |pruduct6 |samsung| 11 |pruduct11| sony | 2 |pruduct2 | lg | 7 |pruduct7 |samsung| 12 |pruduct12| sony | .... , on
i have following query can retrieve same result
select id, title,brand row_number() on (partition brand_id) row_num product_test order row_;
this doesn't work mysql unfortunately need solution based on cakephp find or other apporach
thanks in advance
you can emulate query in following way:
select @rownum := 0, @brand := null; select id , title , brand ( select id , title , brand , @rownum := if(@brand <=> brand, @rownum + 1, 1) row_num , @brand := brand dummy product_test order brand , id ) product_test order row_num , brand , id;
Comments
Post a Comment