insert into Table1(Name,des,num) values ('ltp','thisisbest',10);
select @@identity as 'Id'
select name,Sex=
case Sex
when '1' then '男'
when '0' then '女'
end
from Tablename
select a,b,c from Table1 where a IN (select a from Table2)
select a.title,a.username,b.adddate
from tablename a,(select max(adddate) adddate from tablename where
tablename.title=a.title) b
SQL Server:Select Top 10 * From Tablename Order By NewID()
Access:Select Top 10 * From Tablename Order By Rnd(ID)
Rnd(ID) 其中的ID是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段UserName)
Select Top 10 * From 表Order BY Rnd(Len(UserName))
MySql:Select * From 表Order By Rand() Limit 10
select UserID from Accounts_Users
where UserName is not null
group by UserID
having count (*)>1
SELECT CategoryName,ProductName
FROM Categories LEFT JOIN Products
ON Categories.CategoryID = Products.CategoryID;
SELECT DAY(DATEADD(dd, -DAY('2008-02-13'),DATEADD(mm, 1, '2008-02-13')))
AS 'DayNumber'
1 select * from tablename where column1 like '[A-M]%'
这样可以选择出column字段中首字母在A-M之间的记录
2 select * from tablename where column1 like '[ABC]%'
这样可以选择出column字段中首字母是A或者B或者C的记录
3 select * from tablename where column1 like '[A-CG]%'
这样可以选择出column字段中首字母在A-C之间的或者是G的记录
4 select * from tablename where column1 like '[^C]%'
这样可以选择出column字段中首字母不是C的记录
单字符(关键字:like _):
通过使用下滑线字符(_),可以匹配任意单个字符
select * from tablename where column1 like 'M_crosoft'
匹配特殊字符:([ ] _ - %)
把它们都放到[]中就行了,比如:
select * from tablename where column1 like '%[%]%'
select * into b from a where 1<>1
或
select top 0 * into [b] from [a]
增加列:
alter table Table1 add username varchar(30) not null default ''
修改列:
alter table Table1 alter column username varchar(40)
删除列:
alter table Table1 drop column username
--把所有时间2006-11-1的数据 23点 修改为 21点
update Ad_Browse_20061101
set browsetime='2006-11-01 21'+
SUBSTRING(CONVERT(VARCHAR(30),browsetime,8),3,7)
where DATEPART(Hour,browsetime)=23
http://www.cnblogs.com/jvstudio/archive/2010/01/28/1658502.html
--SELECT ordernumber AS order_no FROM salesorder WHERE ordernumber = 1 FOR XML AUTO, ELEMENTS:for xml Auto 可以生成XML文件。
------------取得一串列的数据。---------------------------------
Select (Stuff((Select ', ' + Address From CU_Address FOR XML PATH('')),1,2,''));