- 5
- 0
- 约1.41万字
- 约 13页
- 2017-04-07 发布于四川
- 举报
常用SQL句语格式积累
常用SQL语句格式积累??一、常用的语句格式积累:?Select top 3 * from class order by id desc 表示查询前3条的数据并且按降来排?select distinct 年龄 from class ?去除重复行的查询select top 2 * from class order by newid() 表示随便查询2行数据select * from class where 年龄=20 or 年龄=19 and 性别=男 表示先查询年龄等于19 并且是男的 在查询所有年龄等于20的人 ?先执行AND查询 再执行ORselect * from class where id not in (select id from class1) 表示查询表一中在表2中没有的数据select * from class where id between 1 and 5 表示查询1到5的数据select * from class where id not between 1 and 5 表示查询不是1到5的数据select * from class where 姓名like 刘% 表示查询刘开头的人select * from class where 姓名like %丹%查询包含丹的人select * from class where 姓名like [刘丹]%查询以刘或者以丹开头的数据select * from class where 姓名like [%刘丹]%查询包含丹或者刘的数据select * from class where 年龄like [^1-2]%查询数据不是以1到2之间开头的select * from class where 年龄like [^刘陈]% 查询不是以刘或者陈开头的数据select * from class where 工作地址is null 表示查询工作地址不是空值的数据select * from class where 工作地址is not null 查询不是空植的数据select * from class where id all(select id from class1)表示查询表2在表一中没有的ID数据select * from class where id = any(select id from class1) 查询表一中和表2相同的IDelect * from class where (性别not in (男))and (not (年龄between 18 and 21))?not语句的查询 在条件语句前面加上NOT?select top 3 * from ?class order by id 前面最三个数据use liudanselect top 3 * from ?class order by id desc 最后三个的数据select ltrim(rtrim(姓名)) from class 里面函数RTRIM代表删除结尾空格数据 外面函数 ltrim 删除前面空格的数据select 姓名+, as 姓名,lower(gege) as gege from class ? ?给姓名的每条数据加上 ,; 把gege 列转换为小写select 姓名+, as 姓名,upper(gege) as gege from class 后面函数把数据全部转换为大写select * from class where month(日期)=9 and year(日期)=1993 and day(日期)=9分别是三个函数 第一个是对指定的日期 月 ,年,日select 年龄-id as a from class 表示用每一行的数据用年龄-id得到的数据+ - * / 都可以用select sum(年龄) as a from class ?求和select * from class where 年龄(select avg(年龄) from class) ?求年龄大于平均值的数据select * from class where 年龄= (select max(年龄) from class) 求年龄最大的、select * from class where 年龄= (select min(年龄) from class) 年龄最小的人select count(*) from class 表中数据总条数select count(年龄) from class 查询年龄不为空的select sum(年龄) from class where 性别=男 得到性别为男的的总年龄数select 年龄,count(*) from class group by 年龄 ? ? ?表示对年龄进行汇总,就是说 对相同年龄
您可能关注的文档
- 巷头村党建作工汇报.doc
- 巷道中心小学综合督导汇报的材料.doc
- 巽宅镇深入学习实践活动调研的报告之.doc
- 市XX局党委2010年度上半年度党建工作情况汇报.doc
- 市人大常委法会制工委.doc
- 市优秀教师秀优教育工作者申报表.doc
- 市区三个交口叉交通岛绿化改造工程.doc
- 市区督学责任区2014年度工作总结.doc
- 市区自备井排查整治工作实施的方案.doc
- 市县级安全产生监管执法证件换证情况汇总表.doc
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
最近下载
- 保障农民工工资支付协调机制和工资预防机制.docx VIP
- (35页PPT)腾讯iOA零信任安全解决方案.pptx
- 供应链管理第章.ppt VIP
- 有机化学醇酚醚.ppt VIP
- 【真题】2025年湖北省公务员考试《申论》试题及答案解析(县乡卷).pdf VIP
- 《2025年人工智能在制造业应用》.docx VIP
- 2018年浙江省杭州市中考科学试卷含答案.docx VIP
- 东北地区自然地理概况课件市公开课一等奖省赛课微课金奖课件.pptx VIP
- Power Up3课后单元测试 - U7 - Unit Test.docx VIP
- EN755-2铝及铝合金挤压杆材,管材及型材 第2部分:机械性能.doc
原创力文档

文档评论(0)