T-SQL简单查询语句
简单查询:
1.最简单查询(查所有数据)
select * from 表名; 注:* 代表所有列
select * from info
2.查询指定列
select code,name from info
3.修改结果集的列名
select code as '代号',name as '姓名' from info
4.条件查询
select * from info where code='p003'
5.多条件查询
查询info表中code为p003或者nation为n001的所有数据
select * from info where code='p003' or nation='n001'
查询info表中code为p004并且nation为n001的数据
select * from info where code='p004' and nation='n001'
6.范围查询
select * from car where price>=40 and price<=60
select * from car where price between 40 and 60
7.离散查询
查询汽车价格在(10,20,30,40,50,60)中出现的汽车信息
select * from car where price=10 or price=20 or price=30 or price=40 or price=50 or price=60
select * from car where price in(10,20,30,40,50,60)
select * from car where price not in(10,20,30,40,50,60)
8.模糊查询(关键字查询)
查询car表里面名称包含奥迪的
select * from car where name like '%奥迪%' %任意n个字符
查询car中名称第二个字符为‘马’的汽车
select * from car where name like '_马%' _任意一个字符


9.排序查询
select * from car order by price asc asc升序(省略)
select * from car order by oil desc desc降序
先按照brand升序排,再按照price降序排
select * from car order by brand,price desc


10.去重查询
select distinct brand from car
11.分页查询
一页显示10条 当前是第3页
select * from chinastates limit 20,10
一页显示m条 当前是第n页
limit (n-1)*m,m
12.聚合函数(统计函数)
select count(areacode) from chinastates #查询数据总条数
select sum(price) from car #求和
select avg(price) from car #求平均
select max(price) from car #求最大值
select min(price) from car #求最小值


13.分组查询
查询汽车表中每个系列下有多少个汽车
select brand,count(*) from car group by brand

查询汽车表中卖的汽车数量大于1的系列
select brand from car group by brand having count(*)>1

T-SQL简单查询语句的更多相关文章
- SQL 简单查询语句 select
select *from emp;//查询emp表内容
- SQL中查询语句的使用
常用SQL查询语句 - myLittleGarden - 博客园 http://www.cnblogs.com/sunada2005/p/3411873.html 一.简单查询语句 1. 查看表结构 ...
- SQL逻辑查询语句执行顺序 需要重新整理
一.SQL语句定义顺序 1 2 3 4 5 6 7 8 9 10 SELECT DISTINCT <select_list> FROM <left_table> <joi ...
- 如何在SQL Server查询语句(Select)中检索存储过程(Store Procedure)的结果集?
如何在SQL Server查询语句(Select)中检索存储过程(Store Procedure)的结果集?(2006-12-14 09:25:36) 与这个问题具有相同性质的其他描述还包括:如何 ...
- python 3 mysql sql逻辑查询语句执行顺序
python 3 mysql sql逻辑查询语句执行顺序 一 .SELECT语句关键字的定义顺序 SELECT DISTINCT <select_list> FROM <left_t ...
- T-SQL简单查询语句(模糊查询)
T-SQL简单查询语句 简单查询: 1.最简单查询(查所有数据) select * from 表名: 注:* 代表所有列 select * from info 2.查询指定列 select code, ...
- mysql第四篇--SQL逻辑查询语句执行顺序
mysql第四篇--SQL逻辑查询语句执行顺序 一.SQL语句定义顺序 SELECT DISTINCT <select_list> FROM <left_table> < ...
- oracle中简单查询语句的格式及执行顺序分析
一条简单的查询sql格式如下: SELECT ... FROM .... [WHERE ...] --过滤单行 [GROUP BY ... [HAVING ...]]--GROUP BY对前面wh ...
- SQL Sever查询语句集锦
一. 简单查询简单的Transact-SQL查询只包括选择列表.FROM子句和WHERE子句.它们分别说明所查询列.查询的表或视图.以及搜索条件等. 例如,下面的语句查询testtable表中姓名为“ ...
- SQL Server SQL高级查询语句小结(转)
--select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select disti ...
随机推荐
- SQL Server 事件通知(Event notifications)
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 基础知识(Rudimentary Knowledge) 事件通知监控DDL(NotifyQue ...
- .NET中的DES对称加密
DES是一种对称加密(Data Encryption Standard)算法,于1977年得到美国政府的正式许可,是一种用56位密钥来加密64位数据的方法.一般密码长度为8个字节,其中56位加密密钥, ...
- Linux服务器安装笔记 汇总
系统 Ubuntu笔记:http://www.cnblogs.com/newsea/p/4746967.html CentOs笔记:http://www.cnblogs.com/newsea/p/47 ...
- Tomcat无故自动退出的问题
我在这篇文章<写一个脚本,自动启动Tomcat>中提到Tomcat会无缘无故退出,而且在日志中找不到原因.后来终于知道为什么了: 由于内存不足,被OOM Killer杀死的!由于是直接被系 ...
- Unit Testing with NSubstitute
These are the contents of my training session about unit testing, and also have some introductions a ...
- Linux RAID卡优化
200 ? "200px" : this.width)!important;} --> 介绍 我们的生产服务器经常会做raid存储,但是单单做了raid就能保证性能高效和数据 ...
- sqlalchemy(一)基本操作
sqlalchemy(一)基本操作 sqlalchemy采用简单的Python语言,为高效和高性能的数据库访问设计,实现了完整的企业级持久模型. 安装 需要安装MySQLdb pip install ...
- ASP.NET MVC 控制器激活(一)
ASP.NET MVC 控制器激活(一) 前言 在路由的篇章中讲解了路由的作用,讲着讲着就到了控制器部分了,从本篇开始来讲解MVC中的控制器,控制器是怎么来的?MVC框架对它做了什么?以及前面有的篇幅 ...
- 《Entity Framework 6 Recipes》中文翻译系列 (39) ------ 第七章 使用对象服务之配置模型和使用单复数服务
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 7-3 配置模型 问题 你想了解配置模型中的各种选项. 解决方案 当你添加一个AD ...
- 机器学习理论知识部分--偏差方差平衡(bias-variance tradeoff)
摘要: 1.常见问题 1.1 什么是偏差与方差? 1.2 为什么会产生过拟合,有哪些方法可以预防或克服过拟合? 2.模型选择例子 3.特征选择例子 4.特征工程与数据预处理例子 内容: 1.常见问题 ...