按列的值排序 [英] Order By values of a column

查看:75
本文介绍了按列的值排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想根据列的值,以特定的顺序返回我的查询结果

。通过示例将更加清楚。让我们说

我的桌子如下


Col1 Col2 Col3

1 A Mark

2 A Rob

3 C Chris

4 B Tom

5 C Harry


我想要按照值的顺序将结果返回到Col2上。

B,C和A.所以,我希望将它排序为:


Col1 Col2 Col3

4 B Tom

3 C Chris

5 C Harry

1 A Mark

2 A Rob


这可能吗?怎么样?


提前致谢,

Lalit

解决方案

< blockquote> singlal写道:

这可能吗?怎么样?




select * from .... where .... by col2 ASC


(或DESC for递减的顺序)


Bernd


-

" Ja,alles meine Herren" FürstLichnowsky。 Ooch det roochen?

Ja,auch das Rauchen。 Ooch im Tiergarten? Ja,auch im Tiergarten

darf geraucht werden,meine Herren。如此努力的死Barrikadenk?mpfe

des 18. M?rz在柏林


singlal写道:

你好,

我想根据列的值,以特定的顺序返回我的查询结果。通过示例将更加清楚。让我们说
我的桌子如下

Col1 Col2 Col3
1 A Mark
2 A Rob
3 C Chris
4 B Tom
5 C Harry

我想要按照值B / C和A的顺序在Col2上返回结果。所以,我想得到它排序为:




选择...

订购

case col2

当''B''然后1

当''C''然后2

当''A''然后3

else 4

结束


singlal写道:



我想根据列的值以特定顺序返回查询结果。通过示例将更加清楚。让我们说
我的桌子如下

Col1 Col2 Col3
1 A Mark
2 A Rob
3 C Chris
4 B Tom
5 C Harry

我想要按照值B / C和A的顺序在Col2上返回结果。所以,我想得到它排序为:

Col1 Col2 Col3
4 B Tom
3 C Chris
5 C Harry
1 A Mark
2 A Rob

这可能吗?怎么样?

提前致谢,
Lalit



by translate(col2,''312'',''ABC''), col1


Hi,

I want the result of my query to be returned in a specific order based
upon values of a column. It will be more clear with example. Let''s say
my table is as below

Col1 Col2 Col3
1 A Mark
2 A Rob
3 C Chris
4 B Tom
5 C Harry

I want the result to be returned sorted on Col2 in the order of values
B, C and A. So, I want to get it sorted as:

Col1 Col2 Col3
4 B Tom
3 C Chris
5 C Harry
1 A Mark
2 A Rob

Is this possible? How?

Thanks in advance,
Lalit

解决方案

singlal wrote:

Is this possible? How?



select * from .... where .... order by col2 ASC

(or DESC for descending order)

Bernd

--
"Ja, alles meine Herren" sprach Fürst Lichnowsky. "Ooch det roochen?"
"Ja, auch das Rauchen." "Ooch im Tiergarten?" "Ja, auch im Tiergarten
darf geraucht werden, meine Herren." Und so endeten die Barrikadenk?mpfe
des 18. M?rz in Berlin


singlal wrote:

Hi,

I want the result of my query to be returned in a specific order based
upon values of a column. It will be more clear with example. Let''s say
my table is as below

Col1 Col2 Col3
1 A Mark
2 A Rob
3 C Chris
4 B Tom
5 C Harry

I want the result to be returned sorted on Col2 in the order of values
B, C and A. So, I want to get it sorted as:



select ...
order by
case col2
when ''B'' then 1
when ''C'' then 2
when ''A'' then 3
else 4
end


singlal wrote:

Hi,

I want the result of my query to be returned in a specific order based
upon values of a column. It will be more clear with example. Let''s say
my table is as below

Col1 Col2 Col3
1 A Mark
2 A Rob
3 C Chris
4 B Tom
5 C Harry

I want the result to be returned sorted on Col2 in the order of values
B, C and A. So, I want to get it sorted as:

Col1 Col2 Col3
4 B Tom
3 C Chris
5 C Harry
1 A Mark
2 A Rob

Is this possible? How?

Thanks in advance,
Lalit


order by translate(col2,''312'',''ABC''), col1


这篇关于按列的值排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆