"H_Date" "AlarmingPoint" "AlarmValue"
2007-12-22 00:00:23 "p1" "2.454 "
2007-12-22 10:00:00 "A1" "23.32" (*)
2007-12-22 10:55:00 "p1" "2.454 "
2007-12-22 11:00:00 "A1" "23.32" (*)
2007-12-22 12:00:00 "p1" "2.454 " (*)
2007-12-22 13:10:00 "A1" "23.32"
2007-12-22 13:10:01 "p1" "2.454 "
2007-12-22 14:23:20 "A1" "23.32"
2007-12-22 15:00:00 "p1" "2.454 " (*)
2007-12-22 16:00:08 "A1" "23.32"
如何提取整点时间的记录,就是后面有 (*)的记录,查询语句怎么写
5 个解决方案
#1
if object_id('tb') is not null
drop table tb
go
create table tb( H_Date datetime,AlarmingPoint varchar(10),AlarmValue float)
insert tb
select '2007-12-22 00:00:23','p1',2.454 union all
select '2007-12-22 10:00:00','A1',23.32 union all
select '2007-12-22 15:00:00','p1',2.454
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
没有把记录全部写出来
功能完全实现了
用这句
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
就欧了
drop table tb
go
create table tb( H_Date datetime,AlarmingPoint varchar(10),AlarmValue float)
insert tb
select '2007-12-22 00:00:23','p1',2.454 union all
select '2007-12-22 10:00:00','A1',23.32 union all
select '2007-12-22 15:00:00','p1',2.454
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
没有把记录全部写出来
功能完全实现了
用这句
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
就欧了
#2
create table tb( H_Date datetime,AlarmingPoint varchar(10),AlarmValue float)
insert tb
select '2007-12-22 00:00:23','p1',2.454 union all
select '2007-12-22 10:00:00','A1',23.32 union all
select '2007-12-22 15:00:00','p1',2.454
select * from tb
where
datename(n,h_date)='0'
and datename(s,h_date)='0'
and datename(ms,h_date)='0'
H_Date AlarmingPoint AlarmValue
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 15:00:00.000 p1 2.454
#3
create table tb(H_Date datetime ,AlarmingPoint varchar(10),AlarmValue varchar(10))
insert into tb values('2007-12-22 00:00:23', 'p1', '2.454')
insert into tb values('2007-12-22 10:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 10:55:00', 'p1', '2.454')
insert into tb values('2007-12-22 11:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 12:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 13:10:00', 'A1', '23.32')
insert into tb values('2007-12-22 13:10:01', 'p1', '2.454')
insert into tb values('2007-12-22 14:23:20', 'A1', '23.32')
insert into tb values('2007-12-22 15:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 16:00:08', 'A1', '23.32')
go
select * from tb where datepart(mi,h_date) = 0 and datepart(ss,h_date) = 0
drop table tb
/*
H_Date AlarmingPoint AlarmValue
----------------------- ------------- ----------
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 11:00:00.000 A1 23.32
2007-12-22 12:00:00.000 p1 2.454
2007-12-22 15:00:00.000 p1 2.454
(4 行受影响)
*/
#4
create table tb(H_Date datetime ,AlarmingPoint varchar(10),AlarmValue varchar(10))
insert into tb values('2007-12-22 00:00:23', 'p1', '2.454')
insert into tb values('2007-12-22 10:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 10:55:00', 'p1', '2.454')
insert into tb values('2007-12-22 11:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 12:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 13:10:00', 'A1', '23.32')
insert into tb values('2007-12-22 13:10:01', 'p1', '2.454')
insert into tb values('2007-12-22 14:23:20', 'A1', '23.32')
insert into tb values('2007-12-22 15:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 16:00:08', 'A1', '23.32')
go
--方法一
select * from tb where datepart(mi,h_date) = 0 and datepart(ss,h_date) = 0
/*
H_Date AlarmingPoint AlarmValue
----------------------- ------------- ----------
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 11:00:00.000 A1 23.32
2007-12-22 12:00:00.000 p1 2.454
2007-12-22 15:00:00.000 p1 2.454
(4 行受影响)
*/
--方法二
select * from tb where right(convert(varchar(19),h_date,120),5) = '00:00'
/*
H_Date AlarmingPoint AlarmValue
----------------------- ------------- ----------
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 11:00:00.000 A1 23.32
2007-12-22 12:00:00.000 p1 2.454
2007-12-22 15:00:00.000 p1 2.454
(4 行受影响)
*/
drop table tb
#5
我想要十五分钟一次的数据 且只是分钟数是15的 其余的秒不是00 的怎么做 比如说 2007-12-22 13:15:11 取这样的数据
#1
if object_id('tb') is not null
drop table tb
go
create table tb( H_Date datetime,AlarmingPoint varchar(10),AlarmValue float)
insert tb
select '2007-12-22 00:00:23','p1',2.454 union all
select '2007-12-22 10:00:00','A1',23.32 union all
select '2007-12-22 15:00:00','p1',2.454
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
没有把记录全部写出来
功能完全实现了
用这句
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
就欧了
drop table tb
go
create table tb( H_Date datetime,AlarmingPoint varchar(10),AlarmValue float)
insert tb
select '2007-12-22 00:00:23','p1',2.454 union all
select '2007-12-22 10:00:00','A1',23.32 union all
select '2007-12-22 15:00:00','p1',2.454
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
没有把记录全部写出来
功能完全实现了
用这句
select * from tb where substring(convert(varchar(100),H_Date,120),15,5)='00:00'
就欧了
#2
create table tb( H_Date datetime,AlarmingPoint varchar(10),AlarmValue float)
insert tb
select '2007-12-22 00:00:23','p1',2.454 union all
select '2007-12-22 10:00:00','A1',23.32 union all
select '2007-12-22 15:00:00','p1',2.454
select * from tb
where
datename(n,h_date)='0'
and datename(s,h_date)='0'
and datename(ms,h_date)='0'
H_Date AlarmingPoint AlarmValue
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 15:00:00.000 p1 2.454
#3
create table tb(H_Date datetime ,AlarmingPoint varchar(10),AlarmValue varchar(10))
insert into tb values('2007-12-22 00:00:23', 'p1', '2.454')
insert into tb values('2007-12-22 10:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 10:55:00', 'p1', '2.454')
insert into tb values('2007-12-22 11:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 12:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 13:10:00', 'A1', '23.32')
insert into tb values('2007-12-22 13:10:01', 'p1', '2.454')
insert into tb values('2007-12-22 14:23:20', 'A1', '23.32')
insert into tb values('2007-12-22 15:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 16:00:08', 'A1', '23.32')
go
select * from tb where datepart(mi,h_date) = 0 and datepart(ss,h_date) = 0
drop table tb
/*
H_Date AlarmingPoint AlarmValue
----------------------- ------------- ----------
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 11:00:00.000 A1 23.32
2007-12-22 12:00:00.000 p1 2.454
2007-12-22 15:00:00.000 p1 2.454
(4 行受影响)
*/
#4
create table tb(H_Date datetime ,AlarmingPoint varchar(10),AlarmValue varchar(10))
insert into tb values('2007-12-22 00:00:23', 'p1', '2.454')
insert into tb values('2007-12-22 10:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 10:55:00', 'p1', '2.454')
insert into tb values('2007-12-22 11:00:00', 'A1', '23.32')
insert into tb values('2007-12-22 12:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 13:10:00', 'A1', '23.32')
insert into tb values('2007-12-22 13:10:01', 'p1', '2.454')
insert into tb values('2007-12-22 14:23:20', 'A1', '23.32')
insert into tb values('2007-12-22 15:00:00', 'p1', '2.454')
insert into tb values('2007-12-22 16:00:08', 'A1', '23.32')
go
--方法一
select * from tb where datepart(mi,h_date) = 0 and datepart(ss,h_date) = 0
/*
H_Date AlarmingPoint AlarmValue
----------------------- ------------- ----------
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 11:00:00.000 A1 23.32
2007-12-22 12:00:00.000 p1 2.454
2007-12-22 15:00:00.000 p1 2.454
(4 行受影响)
*/
--方法二
select * from tb where right(convert(varchar(19),h_date,120),5) = '00:00'
/*
H_Date AlarmingPoint AlarmValue
----------------------- ------------- ----------
2007-12-22 10:00:00.000 A1 23.32
2007-12-22 11:00:00.000 A1 23.32
2007-12-22 12:00:00.000 p1 2.454
2007-12-22 15:00:00.000 p1 2.454
(4 行受影响)
*/
drop table tb
#5
我想要十五分钟一次的数据 且只是分钟数是15的 其余的秒不是00 的怎么做 比如说 2007-12-22 13:15:11 取这样的数据