increment row value does not work properly with where condition I have created sql fiddle as below
it is working fine if i remove where condition(WHERE rg.groupid= 1)  

output without where condition

| ID | RANK | MYORDER | PREVIOUSRANK |
|----|------|---------|--------------|
|  3 |    7 |       1 |            7 |
|  2 |    3 |       2 |            3 |
|  4 |    3 |       2 |            3 |
|  1 |    2 |       3 |            2 |


i want my result order by(ORDER BY mro.rank DESC) but it does not return desired result

SQL Fiddle

CREATE TABLE rankGroup
    (
     id int auto_increment primary key, 
     groupid int
    );

INSERT INTO rankGroup
(groupid)
VALUES
(1),(2),
(1),(1);

CREATE TABLE myRankorder 
    (
     id int auto_increment primary key, 
    groupid int,
     rank int
    );

INSERT INTO myRankorder
(groupid, rank)
VALUES
(1,2),(2,3),
(3,7),(4,3);


Query 1:

SELECT mro.id, mro.rank,
         IF (@prevrank = mro.rank, @rownum, @rownum := @rownum + 1) AS `myorder`,
         @prevrank := mro.rank AS `previousRank`
    FROM `myRankorder` mro
    INNER JOIN `rankGroup` rg
        ON rg.`id` = mro.`groupid`
    cross JOIN
        (SELECT @rownum := 0, @prevrank := 0) const
    WHERE rg.`groupid` = 1  
    ORDER BY mro.rank DESC


Results:

| ID | RANK | MYORDER | PREVIOUSRANK |
|----|------|---------|--------------|
|  3 |    7 |       2 |            7 |
|  4 |    3 |       3 |            3 |
|  1 |    2 |       1 |            2 |


Desired Result

| ID | RANK | MYORDER | PREVIOUSRANK |
|----|------|---------|--------------|
|  3 |    7 |       1 |            7 |
|  4 |    3 |       2 |            3 |
|  1 |    2 |       3 |            2 |
Try it this way

SELECT id, rank,
       @rownum   := IF(rank = @prevrank, @rownum, @rownum + 1) myorder,
       @prevrank := rank previousRank
  FROM 
(
  SELECT mro.id, mro.rank
    FROM myRankorder mro JOIN rankGroup rg
      ON rg.id = mro.groupid 
   WHERE rg.groupid = 1 
   ORDER BY mro.rank DESC
) q CROSS JOIN
(
  SELECT @rownum := 0, @prevrank := NULL
) const


Output:


| ID | RANK | MYORDER | PREVIOUSRANK |
|----|------|---------|--------------|
|  3 |    7 |       1 |            7 |
|  4 |    3 |       2 |            3 |
|  1 |    2 |       3 |            2 |


Here is SQLFiddle demo