i feel obvious i'm struggling. must because it's monday.
i have licenses
table in mysql has fields id (int)
, start_date (date)
, licensable_id (int)
, licensable_type (string)
, fixed_end_point (boolean)
.
i want licenses start date equal or less today, group them licensable_id , licensable_type
, , recently starting one can fixed_end_point
field out of it, along licensable_id
, licensable_type
.
this i'm trying:
select licensable_id, licensable_type, fixed_end_point licenses start_date <= "2016-08-01" group licensable_id, licensable_type order start_date desc;
at moment, order by
field seems being ignored, , it's returning values first license each group, rather recent. can see i'm doing wrong? need make nested query?
you shouldn't thinking group by
. want select recent start_date
each license, given constraints in question. 1 method uses correlated subquery:
select l.* licenses l l.start_date = (select max(l2.start_date) licenses l2 l2.licensable_id = l.licensable_id , l2.licensable_type = l.licensable_type , l2.start_date <= '2016-08-01' );
Comments
Post a Comment