:あなたは、次のようなものを使用することができます。あなたはBの最大値が必要で、GROUP BY句またはHAVING句にも含めないでCの値を得ることはできないので、サブクエリが最善の方法と思われます。
create table #tempints (
a int,
b int,
c int
)
insert into #tempints values (1, 8, 10)
insert into #tempints values (1, 8, 10)
insert into #tempints values (2, 4, 10)
insert into #tempints values (5, 8, 10)
insert into #tempints values (5, 3, 10)
insert into #tempints values (5, 7, 10)
insert into #tempints values (5, 8, 15)
/* this errors out with "Column '#tempints.c' is invalid in the select list because it is not contained in either an
aggregate function or the GROUP BY clause." */
select t1.c, max(t1.b)
from #tempints t1
where t1.a=5
/* this errors with "An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING
clause or a select list, and the column being aggregated is an outer reference." */
select t1.c, max(t1.b)
from #tempints t1, #tempints t2
where t1.a=5 and t2.b=max(t1.b)
/* errors with "Column '#tempints.a' is invalid in the HAVING clause because it is not contained in either an aggregate
function or the GROUP BY clause." */
select c
from #tempints
group by b, c
having a=5 and b=max(b)
drop table #tempints
OPには最新のエントリだけが必要なので、おそらくこれを実行する最善の方法です。 –
ありがとう - 私はちょうど非常に似た問題について考え始めました。私はおそらくこれを私自身で取得していただろうが、ここでそれを読むのと同じくらい速くはない.... – RolandTumble