如何使用多个coulmns进入sql server? [英] how to Use of Order by with multiple coulmns into sql server ?

查看:105
本文介绍了如何使用多个coulmns进入sql server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个进入sql server数据库的表,其中包含一些列,我放了一个select语句,现在我想在多个列上使用order by子句然后按工作顺序排列的方式是什么以及它将如何基于两列以上的顺序排序。



menas使用order by子句按顺序排序所选记录的顺序是什么?按条件排序多列?

i have an table into sql server database which contain some columns and i put an select statment and now i want to use order by clause on more then one columns then what is the way in which order by work and how it will be ordered by based on more then two columns .

menas what is the way to order selected record to order using order by clause with multiple column into order by condition?

推荐答案

如果您在查询中提供两个或更多order by子句,它们将根据这些列的顺序进行排序。

例如从Table1中选择*按colA,colB 将首先按 colA 对记录进行排序,然后在同一<$的集合中c $ c> colA 记录,按 colB 排序。



同样你可以定义不同的排序顺序,例如从表1中选择*按colA desc,colB asc
If you provide two or more order by clauses in your query, they will be sorted based on the order of these columns.
For e.g. select * from Table1 order by colA, colB will first sort records by colA and then within the set of same colA records, sort by colB.

Similarly you can define different sort orders for e.g. select * from Table1 order by colA desc, colB asc








检查这个...



如何将group by子句用于sql server? [ ^ ]



希望这会对你有所帮助。



干杯
Hi,


Check this...

how to use group by clause into sql server?[^]

Hope this will help you.

Cheers


考虑我有一个客户地址详情tbale与以下列



1 cust id

2 cust name

3 city

4州

5国家





现在我将通过以下方式查找记录客户名称,城市和州明智





select * from customer_address_master

order by customer_name,city,state



它会告诉我



客户明智然后找到城市明智并最终找到州明智的记录



尝试一下,这将会理解你
consider i have one customer address details tbale with below column

1 cust id
2 cust name
3 city
4 state
5 country


now Iam going to find records by customer name , city and state wise


select * from customer_address_master
order by customer_name , city , state

it will show me

customer wise then find city wise and finally find state wise records

Try it , this wil understand you


这篇关于如何使用多个coulmns进入sql server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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