博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL基础语句(提升)
阅读量:4581 次
发布时间:2019-06-09

本文共 1032 字,大约阅读时间需要 3 分钟。

1、复制表(只复制结构,源表名:a 新表名:b)

select * into b from a where 1<>1

2、拷贝表

insert into b(a,b,c) select d,e,f from b;

3、跨数据库之间表的拷贝(具体数据使用绝对路径)

insert into b(a,b,c) select d,e,f from b in '数据库路径' where 条件

4、子查询(表名1:a 表名2:b)

select a,b,c from a where a in(select d from b) 或者:select a,b,c from a where a

in(1,2,3)

5、显示文章、提交人和最后回复时间

select a.title,username,b.adddate from table a,(select max(adddate)

adddate from table where table.title=a.title)b

6、两张表关联,删除在表2中有表1没有的数据

delete from table1 where not exists(select * from table2 where table1.id=table2.id)

7、日程安排提前五分钟提醒

select * from 日程安排 where datediff('minute',开始时间,getdate())>=5

8、数据库分页

select top 10 b.* from (select top 20 主键字段,排序字段 from 表名 order by 排序

字段 desc)a,表名 b where b.主键字段=a.主键字段 order by a.排序字段

具体实现:

declare @start int,@end int

@sql nvarchar(500)

set sql='select top'+str(@end-@start+1)+'+from T where rid not

in(select top'+str(@str-1)+'rid from t where rid>-1)'

exec sp_executesql @sql

9、前十条记录

select top 10 * from table1 where 范围

 

转载于:https://www.cnblogs.com/TTTTTZ/p/5098969.html

你可能感兴趣的文章
查找不同的木棍
查看>>
面试题:顺时针打印矩阵
查看>>
DataSet、DataTable、DataRow、DataColumn区别及使用实例
查看>>
python 特殊方法
查看>>
Python3 练习笔记四
查看>>
装箱问题
查看>>
Android线程管理(一)——线程通信
查看>>
vim 使用技巧
查看>>
Periodic String UVa1225
查看>>
Android 演示 DownloadManager——Android 下载 apk 包并安装
查看>>
采用oracle存储过程读取excel文件更新表
查看>>
固定虚拟机中windows系统的ip地址
查看>>
【转】正则应用实例,如将多个空格改为1个空格
查看>>
移动端自动打包平台
查看>>
gradle 使用总结
查看>>
C#函数式程序设计初探——重构应用篇
查看>>
兼容的获取选择文本方法
查看>>
谈一谈git和SVN两大版本管理工具。
查看>>
【1】Bootstrap入门引言
查看>>
PhpExcel中文帮助手册|PhpExcel使用方法
查看>>