sql视图:http://www.cnblogs.com/CareySon/archive/2011/12/07/2279522.html
sql索引:http://www.cnblogs.com/AK2012/archive/2013/01/04/2844283.html
sql复合索引:http://www.cnblogs.com/worfdream/archive/2010/05/21/1740752.html
sql取随机数据:http://www.cnblogs.com/lyhabc/p/3826872.html
sql临时表:http://www.cnblogs.com/jeffwongishandsome/archive/2009/08/05/1526466.html
是否存在表:http://www.cnblogs.com/yugen/archive/2010/07/25/1784749.html
exec sp_executesql @sql,N'@count int out',@count out
sql日期差:select Convert(decimal(18,2),(datediff(MINUTE,'2012/8/1 15:29:18','2012/8/3')/60.0)) as daysum
-- 去掉一个最高分、一个最低分,取平均数
select (sum(order_pay) - MAX(order_pay) - MIN(order_pay))/(count(1) - 2) from orders
-- 计算每天、访客数、总操作次数、平均操作次数
select
CONVERT(nvarchar(10),log_time,120) AS logDay,
COUNT(distinct user_id) AS userCount,
COUNT(opr_id) AS totalOpr,
CONVERT(decimal(18,2),CONVERT(decimal(18,2),COUNT(opr_id))/CONVERT(decimal(18,2),COUNT(distinct user_id))) AS avgOpr
from [dbo].[tracking_log]
group by CONVERT(nvarchar(10),log_time,120)
order by CONVERT(nvarchar(10),log_time,120) asc