一些不错的sql语句(面试可能碰到哦!)
例子1) 一个表Table_1 有两个字段
id number,
name varchar2(7)
其中id是主键,name有重复记录
要求删除name字段重复的记录,保留其中id字段值最小的那条记录
如:
id name
1 test
2 test
3 test
4 test1
5 test1
6 test1
删完 了保留
1 test
4 test1
&nbs
相关文档:
1 Export data to existing EXCEL file
from SQL Server table
insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;',
'SELECT * from [SheetName$]') select * from SQLServerTable
2 Export data from Excel to new SQL Server table
select *
into SQLServerTab ......
/*获取重复记录中较小的那个ID*/ create table tmp_Repeat as select min(id) as id from poi group by idcode having count(*) >1; /*备份删除的数据*/ select * from poi where id in (select id from tmp_repeat) /*删除重复记录中ID较小的那条
select replace('阿桂是个好孩子','阿桂','小贤') from du ......
1.判断一个临时表是否存在
if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U')
drop table #tempcitys
注意tempdb后面是两个. 不是一个的
---临时表
if exists(select * from tempdb..sysobjects where name like &lsqu ......
SQL存储过程分页算法研究(支持千万级)
1.“俄罗斯存储过程”的改良版
CREATE procedure pagination1
(@pagesize int, --页面大小,如每页存储20条记录
@pageindex int --当前页码)
as set nocount on
begin
declare @indextable table(id int identity(1,1),nid int) --定义表变量
declare @PageL ......
MySQL Date 函数
下面的表格列出了 MySQL 中最重要的内建日期函数:
函数描述
NOW()
返回当前的日期和时间
CURDATE()
返回当前的日期
CURTIME()
返回当前的时间
DATE()
提取日期或日期/时间表达式的日期部分
EXTRACT()
返回日期/时间按的单独部分
DATE_ADD()
给日期添加指定的时间间隔
DATE_SUB()
从日期 ......