sql - MS Access query -
i using ms access. have table named changes having columns
( cno (int) , tno (int), date_c).
i want write sql query displays recent date , group cno. want display tno.
select tno, cno, max(date_c) changes [date_c] in (select [date_c] changes [date_c]<=[enter date]) group cno;
there 7 ways in sql (because there :) , oft asked question on stackoverflow. here's one: (i've omitted date_c <= [enter date]
parameter clarity , because can't test -- i'm not using access interface!):
select distinct c1.tno, c1.cno, dt1.c_most_recent_date changes c1 inner join ( select c2.cno, max(c2.c_date) c_most_recent_date changes c2 group c2.cno ) dt1 on c1.cno = dt1.cno; , c1.c_date = dt1.c_most_recent_date;
and here's another:
select distinct c1.tno, c1.cno, c1.c_date c_most_recent_date changes c1 not exists ( select * changes c2 c2.cno = c1.cno , c1.c_date < c2.c_date );
Comments
Post a Comment