Select all fields with group by clause in Ms. Access -
i have table contain checktime, userid, , checktype. checktime type datetime. want these data without duplicate checktime date. example data this:
userid | checktime | checktype 1 | 2016-05-01 06:58:00 | 1 | 2016-05-01 06:59:00 | 1 | 2016-05-02 06:58:00 | 1 | 2016-05-02 06:58:10 | 1 | 2016-05-02 06:59:00 |
does know how remove duplicate date? so, above data, can result this:
userid | checktime | checktype 1 | 2016-05-01 06:58:00 | 1 | 2016-05-02 06:58:00 |
i tried use distinct, doesn't works, because have different time each checktime. , use group clause, can give me result 1 field.
my query right this:
select userid, checktype, checktime, day(checktime) checkinout userid = 259 , month(checktime)='5' , year(checktime)='2016' , checktype = 'i' group day(checktime) order day(checktime) asc
and cames error aggregate function.
do need time?
select distinct userid, format([checktime],"yyyy/mm/dd") checkdate, checktype checkinout;
results in 2 records without time
userid | checktime | checktype 1 | 2016-05-01 | 1 | 2016-05-02 |
or looking first time each unique day? it
edit: added order date clause
select distinct userid, checktype, format([checktime],"yyyy/mm/dd") checkdate, min(checkinout.checktime) firstchecktime checkinout (month([checktime])=5) , (year([checktime])=2016) group userid, checktype, format([checktime],"yyyy/mm/dd") having ((userid=1) , (checktype="i")) order format([checktime],"yyyy/mm/dd");
looks this:
userid checktype checkdate firstchecktime 1 2016/05/01 2016-05-01 06:58:00 1 2016/05/02 2016-05-02 06:58:00
Comments
Post a Comment