Sql Server中的月相关查询 [英] Month Related Query in Sql Server

查看:71
本文介绍了Sql Server中的月相关查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有一列是DOB(出生日期)



在该数据库中,DOB的所有员工详细信息都插入了记录。



DOB(出生日期格式为mm / dd / yyyy)



示例如下;



DOB(IN数据库DOB有这样的名字)格式为mm / dd / yyyy)



9/16 / 1945

4/10/1952

6/30/1978

4/19/1981

4 / 5/44

4/11/1948

3/12/77

12/13/1985

6/14/1974

1/3/1944

8/7/1950

11/5/1977

8/11/1974

2/16/1941

7/23/1944

7/23/1968

3/7/1974

6/27/1945

11/3/1952

4/10/1976

3/29/1987

11/2/1956

12/14/1987

5/29/1989

9/24/1973

10/26/1978

9/25/2001

5/1 / 1984

8/4/1977

10/21/2008



i希望将输出作为MONTH安排在所有月的升序中。

从1月到Decmeber的升序。



表示如何编写查询。



  选择名称,CONVERT(varchar(11),DOB,106)AS Date_of_birth,Mobileno as Mobile_Number,CONVERT(varchar(11),Weddingday,106)AS Wedding_Day,EMail as来自BirthDayWish的E_Mail,其中Active ='A'ORDER BY Name; 





来自上面的查询如何写月按升序显示。

解决方案

添加DATENAME(月,DOB)AS''出生月''并按月(DOB)(月份)进行订购返回一个数字,datename会按字母顺序给你几个月)


使用它:



 < span class =code-keyword> SELECT  * 
FROM tbl_userwritereviews
ORDER BY DATEPART(mm,日期


您好,



请尝试以下方法,


要进行排序,请使用以下内容,而不是每年使用以下内容,



选择CONVERT (varchar(11),d.dob,106),DATENAME(MONTH,d.dob),DATEPART(MONTH,d.dob)来自DATEPART(MONTH,d.dob)asc的驱动程序d 





按年份,日期和月份排序使用以下内容,



从d.dob asc 

<驱动程序d顺序中选择CONVERT(varchar(11),d.dob,106),DATENAME(MONTH,d.dob),DATEPART(MONTH,d.dob) / BLOCKQUOTE>

i have one column in database that is DOB(Date of Birth)

in that database all employee details of DOB has inserted records are there.

DOB(Date of birth format as mm/dd/yyyy)

Example as follows;

DOB( IN Database DOB has name like that) Format as mm/dd/yyyy)

9/16/1945
4/10/1952
6/30/1978
4/19/1981
4/5/44
4/11/1948
3/12/77
12/13/1985
6/14/1974
1/3/1944
8/7/1950
11/5/1977
8/11/1974
2/16/1941
7/23/1944
7/23/1968
3/7/1974
6/27/1945
11/3/1952
4/10/1976
3/29/1987
11/2/1956
12/14/1987
5/29/1989
9/24/1973
10/26/1978
9/25/2001
5/1/1984
8/4/1977
10/21/2008

i want the output as MONTH to be arranged in Ascending Order All Months.
From January to Decmeber in Ascending Order.

for that how to write the query.

"select Name, CONVERT(varchar(11), DOB, 106)  AS Date_of_birth,Mobileno as Mobile_Number, CONVERT(varchar(11), Weddingday, 106) AS Wedding_Day,EMail as E_Mail from BirthDayWish where Active = 'A' ORDER BY Name";



from the above query how to write the Month to be Displayed in ascending order.

解决方案

add DATENAME(month, DOB) AS ''Birth Month'' and they do an order by month(DOB) ( month returns a number, datename would give you months alphabetically )


Use This:

SELECT  *
FROM         tbl_userwritereviews
ORDER BY DATEPART(mm, date)


Hi,

Try the following,

To sort, Instead of year only by month use the following,

Select CONVERT(varchar(11),d.dob,106), DATENAME(MONTH,d.dob), DATEPART(MONTH,d.dob) from driver d order by DATEPART(MONTH,d.dob) asc



To sort by year, date and month use the following,

Select CONVERT(varchar(11),d.dob,106), DATENAME(MONTH,d.dob), DATEPART(MONTH,d.dob) from driver d order by d.dob asc


这篇关于Sql Server中的月相关查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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