码迷,mamicode.com
首页 > 数据库 > 详细

SqlServer--数据检索(查询)

时间:2016-12-16 01:03:24      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:data   排列   add   res   时间   分行   显示   别名   检索   

 

use  MyDataBase1

-- * 表示显示所有列

-- 查询语句没有加where条件表示查询所有行

select *from TblStudent

---只查询表中的部分列

select tsid,tsname,tsgender from TblStudent

--根据条件,只查询部分行(使用where条件筛选部分行显示)

select * from TblStudent where tsclassId=5

--为查询结果集中的列起别名

select tsid as 学生编号,tsname as 学生姓名,tsgender as 性别 from TblStudent

--也可以这样排列

select

tsid as 学生编号,

tsname as 学生姓名,

tsgender as 性别

from TblStudent

 

select

tsid ‘(学生 编号)‘, --可以输出空格

tsname 学生 姓名, --不能输出空格

tsgender 性别

from TblStudent

 

select

学生编号=tsid,

学生姓名=tsname,

性别=tsgender

from TblStudent

 

 

select

学生编号=tsid,

学生姓名=tsname,

性别=tsgender,

婚否=‘否‘

from TblStudent

 

--并不是说select必须配合from一起来使用,可以单独使用select

select

当前系统时间=getdate()

 

select

班长=‘严蒙‘,

班花=‘待定‘,

班草=‘待定‘,

班主任=‘宋词‘

 

--distinct关键字,针对已经查询出的结果然后去除重复

select distinct * from TblStudent

select distinct tsname,tsgender,tsaddress from TblStudent

 

SqlServer--数据检索(查询)

标签:data   排列   add   res   时间   分行   显示   别名   检索   

原文地址:http://www.cnblogs.com/hao-1234-1234/p/6185223.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!