0

我有一张桌子

表格1

id   city    projects       Rank
----------------------------------
1    che        p2           2
2    bang       p1           1
3    che        p4           1
4    bang       p3           2
5    bang       p5           3
6    gur        p6           1
7    gur        p7           2

根据排名我想选择我想要的城市和项目

   bang       p1            1
    che        p4           1
    gur        p6           1
    che        p2           2
    bang       p3           2
    gur        p7           2
    bang       p5           3

select * from table1 where Rank = ?

4

6 回答 6

2
select city,project,rank from table1 order by rank,project,city
于 2012-11-21T13:11:38.730 回答
1

尝试这个

 select city, projects, Rank from table order by Rank
于 2012-11-21T13:12:37.480 回答
1

在查询中使用ORDER BY子句。

SELECT city, projects, rank FROM table1 
order by rank
于 2012-11-21T13:13:05.480 回答
1

这里的很多答案都很好。

然而,在 SQL 中对语言结构使用 UPPERCASE 是常见的做法:

SELECT city,project,rank FROM table1 ORDER BY rank,project;

:-)

于 2012-11-21T13:15:06.270 回答
1

我希望这能帮到您:

select city, projects, Rank from table1 
order by Rank, city, projects

您还可以在order by子句中使用位置:

select city, projects, Rank from table1 
order by 3,1,2

0底部的解决方案:

 select city, projects, Rank from table1 
    order by
    case 
     when Rank>0 then 1
     else 2
    end,
    Rank, city, projects
于 2012-11-21T13:11:45.500 回答
0

尝试这个...

select city,projects,rank from table1 group by rank order by rank,city,projects;
于 2012-11-21T13:10:13.070 回答