日期:2014-05-17 浏览次数:20632 次
create table TestGetMaxTime
(
name varchar(20),
time datetime,
c1 decimal(16,4),
c2 decimal(16,4),
)
insert into TestGetMaxTime values ('A','2013-01-30 01:00:00',12,2)
insert into TestGetMaxTime values('A','2013-01-30 02:00:00',12,4)
insert into TestGetMaxTime values('A','2013-01-30 03:00:00',12,3)
insert into TestGetMaxTime values('B','2013-01-30 01:00:00',12,6)
insert into TestGetMaxTime values('B','2013-01-30 02:00:00',12,1)
insert into TestGetMaxTime values('B','2013-01-30 03:00:00',12,2)
select * from TestGetMaxTime
drop table TestGetMaxTime
max(c1/c2)
USE test
GO
create table TestGetMaxTime
(
name varchar(20),
time datetime,
c1 decimal(16,4),
c2 decimal(16,4),
)
insert into TestGetMaxTime values ('A','2013-01-30 01:00:00',12,2)
insert into TestGetMaxTime values('A','2013-01-30 02:00:00',12,4)
insert into TestGetMaxTime values('A','2013-01-30 03:00:00',12,3)
insert into TestGetMaxTime values('B','2013-01-30 01:00:00',12,6)
insert into TestGetMaxTime values('B','2013-01-30 02:00:00',12,1)
insert into TestGetMaxTime values('B','2013-01-30 03:00:00',12,2)
select
name,time
from TestGetMaxTime AS a
WHERE NOT EXISTS(SELECT 1 FROM TestGetMaxTime AS x
WHERE x.name=a.name
AND x.c1/x.c2 > a.c1/a.c2
)
drop table TestGetMaxTime
/*
name time
----- -----------------------
A 2013-01-30 01:00:00.000
B 2013-01-30 02:00:00.000
*/