SQL所有查询语句与操作规范

SQL所有查询语句与操作规范

志在指尖已经将数据库的与数据表sql脚本数据库上传了 点击下方链接去下载吧!

sql插入数据表的脚本

数据库查询语句

数据库查询语句

1 全字段查询

1】查询stuInfo表的所有信息

select * from stuInfo

2 部分字段查询

2】查询stuInfo表的stuNamestuIdentitystuSex

Select stuName,stuIdentity,stuSex

From stuInfo

3 字段换名查询

3】查询stuInfo表的stuNamestuIdentitystuSex,将列名换成姓名、身份证号和性别呈现。

Select stuName 姓名,stuIdentity 身份证号,stuSex 性别

From stuInfo

或:Select stuName as 姓名,stuIdentity as 身份证号,stuSex as 性别…

或: Select 姓名=stuName,身份证号=stuIdentity,性别=stuSex …

4 列运算查询

4】查询学生的姓名(stuName)和完整的班级号(schId+classID

Select stuName as 姓名,schId+classID as 班级号 From stuInfo

5 函数查询

日期函数:getDate()、Year()、month()、Day()、DatePart()、DateDiff()…

字符串函数:len()、right()、left()、substring()…

类型转换:Cast()、convert()

…(更多函数参阅SQL Server帮助文档)

【例5】查询日期数据

select getDate()

select year(getDate())

select month(getDate())

select Day(getDate())

select datepart(year,getDate())

select datepart(month,getDate())as ‘月份’

select datepart(day,getDate()) as ‘日’

select datepart(hour,getDate())

select datepart(minute,getDate())

select datepart(second,getDate())as ‘秒’

select datepart(weekDay,getDate())-1 as ‘星期几’

6】查询stuInfo表的学生出生日期,从stuIdentity的第7到第14获取。

select substring(stuidentity,7,8) as 出生日期 from stuInfo

或:

select right(left(stuidentity,14) ,8) as 出生日期 from stuInfo

7】查询stuInfo表的学生姓名及年龄。

select stuName 姓名,年龄=

datediff(year,cast(substring(stuidentity,7,8) as datetime),getDate()) from stuInfo

下面是大部分sql查询语句代码 因为时间原因就不写出来了

select*from stuInfo --全字段查询
select stuName from stuInfo --部分字段查询
select stuName,stuIdentity,stuSex from stuInfo--字段换名查询
select stuName as 姓名,stuIdentity 身份证号,stuSex as 性别 from stuInfo--字段换名查询
select stuName as 姓名,schId+classId as 班级号 from stuInfo--函数查询
select getDate()
select year(getDate())
select month(getDate())
select Day(getDate())
select datepart(year,getDate())
select datepart(month,getDate())as '月份'
select datepart(day,getDate()) as '日'
select datepart(hour,getDate())
select datepart(minute,getDate())
select datepart(second,getDate())as '秒'
select datepart(weekDay,getDate())-1 as '星期几'
© 版权声明
好牛新坐标
版权声明:
1、IT大王遵守相关法律法规,由于本站资源全部来源于网络程序/投稿,故资源量太大无法一一准确核实资源侵权的真实性;
2、出于传递信息之目的,故IT大王可能会误刊发损害或影响您的合法权益,请您积极与我们联系处理(所有内容不代表本站观点与立场);
3、因时间、精力有限,我们无法一一核实每一条消息的真实性,但我们会在发布之前尽最大努力来核实这些信息;
4、无论出于何种目的要求本站删除内容,您均需要提供根据国家版权局发布的示范格式
《要求删除或断开链接侵权网络内容的通知》:https://itdw.cn/ziliao/sfgs.pdf,
国家知识产权局《要求删除或断开链接侵权网络内容的通知》填写说明: http://www.ncac.gov.cn/chinacopyright/contents/12227/342400.shtml
未按照国家知识产权局格式通知一律不予处理;请按照此通知格式填写发至本站的邮箱 wl6@163.com

相关文章