如何更改行计数顺序

时间:2016-08-07 16:18:46

标签: mysql

我正在使用以下MySql查询,该查询是从我之前的问题中获得的。

SELECT row_count,id FROM
    (
        SELECT
        IF(i.id = @sameIndustryId, @a :=@a + 1, @a := 1) AS row_count,
            @sameIndustryId := i.id,
            p.*, u.first_name,
            u.designation,
            u.profile_picture,
            i. NAME AS industry,
            l.location
        FROM
            industry i,
            projects p,
            location l,
            user_profile u,
           (SELECT @a := 1, @sameIndustryId := 0 ) var
        WHERE
            u.uid = p.uid
        AND p.location_id = l.id
        AND i.id = p.industry_id
        AND p.abstract != ''
        ORDER BY i.id,p.id desc
    ) t

以上查询提供以下输出;

enter image description here

但我希望row_count按升序排列。如何实现

我的预期输出就像(我刚刚在这里显示了industry_id; row_count是基于此创建的)

enter image description here

1 个答案:

答案 0 :(得分:1)

之后使用order by row_count asc