SQL常用语句

SQL常用语句

 

1.简单的查询

查询testtable表中姓名为张三的nickname字段和email字段

select nickname, email from testtable  where name='张三'

 

2.查询结果集合中数据的排列顺序与选择列表中所指定的列明排列顺序相同

 select  nickname,email from  testtable

 

3.更改标题

select var1=nickname,var2=email from testtable

 

4.限制返回的行数

返回前20条或者前20%的行数

select  top 20 * from testtable 

select top 20 percent  *  from testtable

 

 

FROM子句

 

1.FROM子句指定select语句查询及与查询相关的表或视图。在from子句中最多可以指定256个表或视图,他们之间用逗号分隔。

 

select  username,citytable.cityid  from  usertable,citytable  where  usertable.cityid=citytable.cityid

 

 

2.在from子句中可用以下两种格式为表或视图指定别名:

表明   as  别名

表明    别名

select  username,b.cityid  from  usertable   a,citytable    b   where  a.cityid=b.cityid

 

查找usertable表中字段username,要求不包含A 又要包含B的所有字段

select  username  from  usertable  (select username from usertable  where username<>'*A*') as t  where  t.username ='*B*'

 

 

 where子句

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值