Sql基本语句的学习
--查询每个人订饭的次数
select username as 姓名, count(*) as 次数 from orderitems group by UserName having count(*)=1
order by 姓名 desc
select distinct username as 未注册姓名 from orderitems
where username not in (select [Name] from Person)
select distinct username as 已注册姓名 from orderitems where username
in (select [Name] from Person)
--索引为31-40的数据
select top 10 * from orderitems where ID not in (select top 30 ID from orderitems)
--复制数据
insert into distinctselect(UserName,State,OrderTime) select UserName,State,OrderTime from orderitems
--去除所有重复的记录(完全重复)
select distinct UserName ,ID, State,OrderTime into #Table1 from [distinctselect]
delete from [distinctselect]
insert into [distinctselect](UserName,State,OrderTime) select UserName,State,OrderTime from #Table1
drop table #Table1
--删除某列重复的记录
delete t
from [distinctselect] t
where exists (
select 1 from [distinctselect] where username=t.username and id<t.id)
select * from [distinctselect] order by username
delete from [distinctselect]
相关文档:
利用SQL2000的定时备份功能,能很好对服务器上的重要数据信息进行完整的定时备份,以便在服务器瘫痪或数据库出现损坏时及时的进行恢复工作,以确保平时的工作能正常的进行。下面向大家介绍一下SQL2000定期备份的设置方法,具体如下:
1. 打开SQL2000的企业管理器
2.&nbs ......
在使用CLR存储过程中遇到的一些问题,在这里进行记录:
打开CLR的支持
--在Sql Server中执行这段代码可以开启CLR
exec sp_configure 'show advanced options', '1';
go
reconfigure;
go
exec sp_configure 'clr enabled', '1'
go
reconfigure;
exec sp_c ......
sql server日期时间转字符串
日期时间转字符串
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
Select CONVERT(varchar(1 ......