SQL中以日期为条件统计方法
/*统计每天数据总量三种方法:
select convert(char(10),happentime ,120) as date ,count(1) from table1
group by convert(char(10),happentime ,120) order by date desc
select day(happentime) as date,count(*) from table1
group by day(happentime) order by date desc
SELECT left([happentime],5),count (1)
from [database].[dbo].[ table1]
group by left([happentime],5)
order by left([happentime],5)
说明:happentime为表字段名;
大家分别测试下 left([happentime],20) 与 convert(char(10),happentime ,120) 、day(happentime) 两者的区别,对于新人来说,从left([happentime],5) 来看结果往往看不出来与其他两个的不同。
如果不明白语句如何写,请参考如下:
select convert(char(10),happentime ,120) from table1
SELECT left([happentime],5) from table1
SELECT left([happentime],5) from table1
相关文档:
没有引用关系的表
1. 联表更新
update a set a.education = '本科' from NT_UserInfo a ,NT_User b where a.UserID=b.UserID and b.email = 'carlfan2008@163.com'
2. 联表查询
select a.*,b.* from nt_user as a, nt_userinfo as b where a.userid = b.userid and Email = 'carlfan2008@163.com ......
1 :普通SQL语句可以用Exec执行
例: Select * from tableName
Exec('select * from tableName')
& ......
DECLARE @dt datetime
SET @dt=GETDATE()
DECLARE @number int
SET @number=3
--1.指定日期该年的第一天或最后一天
--A. 年的第一天
SELECT CONVERT(char(5),@dt,120)+'1-1'
--B. 年的最后一天
SELECT CONVERT(char(5),@dt,120)+'12-31'
--2.指定日期所在季度的第一天或最后一天
--A. 季度的第一天
SELECT CON ......
使用整数数据的精确数字数据类型。
bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。
存储大小为 8 个字节。
int 从 -2^31 (-2,147,483,648) 到 2^31 - 1 (2,147,483,64 ......
例如查找关于对library ....等待事件有贡献的SQL
select sql_text from V$sqlarea where (address,hash_value) in
(select sql_address,sql_hash_value from v$session where event like 'library%');
此语句只能运行于10g版本以上,因为10g中v$session视图包含了等待事件的信息了,9i中没有 ......