T-SQL简单查询语句(模糊查询)
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语句模糊查询字符串的两种写法
Sql语句模糊查询有两种写法,一种是在jdbcTemplate的查询方法参数里拼接字符串%,一种是在Sql语句里拼接%字符串. public class IsNameDaoImpl implement ...
- 在SQL Server中用好模糊查询指令LIKE
简介:like在sql中的使用 在SQL Server中用好模糊查询指令LIKE 查询是SQL Server中重要的功能,而在查询中将Like用上,可以搜索到一些意想不到的结果和效果,like的神奇之 ...
- 在SQL Server中用好模糊查询指令LIKE (转载)
like在sql中的使用:在SQL Server中用好模糊查询指令LIKE:查询是SQL Server中重要的功能,而在查询中将Like用上,可以搜索到一些意想不到的结果和效果,like的神奇 一.一 ...
- T-SQL:SQL Server-数据库查询语句基本查询
ylbtech-SQL Server-Basic:SQL Server-数据库查询语句基本查询 SQL Server 数据库查询语句基本查询. 1,数据库查询语句基本查询 数据库 SQL Serv ...
- SQL查询语句,怎样查询重复数据
SQL查询语句,怎样查询重复数据 2012-02-22 14:50神奇的马骁勇 | 浏览 0 次 有表A, 中有字段id, name, memo现在有很多id重复的数据,怎么把这些重复的都查出来?gr ...
- 【知识库】-数据库_MySQL之基本数据查询:子查询、分组查询、模糊查询
简书作者:seay 文章出处: 关系数据库SQL之基本数据查询:子查询.分组查询.模糊查询 回顾:[知识库]-数据库_MySQL常用SQL语句语法大全示例 Learn [已经过测试校验] 一.简单查询 ...
- Asp.net Core C#进行筛选、过滤、使用PredicateBuilder进行动态拼接lamdba表达式树并用作条件精准查询,模糊查询
在asp.net core.asp.net 中做where条件过滤筛选的时候写的长而繁琐不利于维护,用PredicateBuilder进行筛选.过滤.LInq配合Ef.core进行动态拼接lamdba ...
- 10月30日下午 PHP精确查询(模糊查询、模糊+关键字共同查询)
1.一个条件的模糊查询 <body> <br /> <form action="main.php" method="post"&g ...
- 【CoreData】分页查询和模糊查询
在CoreData实际使用中,分页查询和模糊查询是必不可少的,接下来演示一下: 首先 // 1.创建模型文件 (相当于一个数据库里的表) // New File ———— CoreData ———— ...
- Linq动态查询与模糊查询 ---转
Linq动态查询与模糊查询(带源码示例) 继LINQ动态组合查询PredicateExtensions讲解 ----- 在用上面的方法时遇到了些问题 解决 LINQ to Entities 不支持 L ...
随机推荐
- poj 2100(尺取法)
Graveyard Design Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 6107 Accepted: 1444 ...
- ASP.NET MVC 利用Razor引擎生成静态页
实现原理及步骤: 1.通过ViewEngines.Engines.FindView查找到对应的视图,如果是部分视图,则用:ViewEngines.Engines.FindPartialView: 2. ...
- react 使用antd导航组件实现事件传递并局部刷新DOM
我们要实现一个通过点击顶部导航来查询左侧菜单的一个功能 在这个功能中,我们要应用到onClick={this.headNavMenuList.bind(this)}方法来传递点击 不同按钮来传递不同的 ...
- C++ primer分章节快速回顾
第三章: 1,sozeof(int): int n_int=INT_MAX; sizeof n_int;(对变量括号可选) 2,#include<climits>包含一些类型的最大值3,c ...
- python-re之中文匹配
#coding=utf-8 import re import chardet#检测网页编码形式的模块 p = re.compile(r'\d+') print p.findall('one1two2t ...
- Leetcode | Construct Binary Tree from Inorder and (Preorder or Postorder) Traversal
Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...
- js判断是否是PC,IOS,Android客户端
写在前面 在项目中使用html5,需要针对不同的客户端浏览器有不一样的处理方式,这就需要对请求中的useragent进行分析,并进行处理. 一个例子 <%@ Page Language=&quo ...
- Beginning Auto Layout Tutorial in iOS 7: Part 2
Auto Layout to the rescue! 接下来就看看如何使用Auto Layout来实现这个效果. 首先移除viewWillLayoutSubviews方法,选择Main.storybo ...
- iOS 5的文件存储策略应对
苹果在iOS 5系统时,对app的文件存储提出了新的要求.从它的guildline来看,是推荐开发者尽量把app生成的文件放在Caches目录下的.原文如下: Only user-generated ...
- ADO.NET-temple
ylbtech-ADO.NET:ADO.NET-Oracle|SQLServer|MySql|Access|Excel-dddd 介绍及讲解 1.A,插入数据(Create) 1.B,读取数据(Rea ...