mysql - How to get the last 3 group created at the same time? -
i'm trying last 3 groups of coupons created @ same date. table looks so:
+-------------+-----------+ |coupon name |created @ | +-------------+-----------+ |c1 |2016-01-17 | |c2 |2016-01-17 | |c3 |2016-01-18 | |c4 |2016-01-19 | |c5 |2016-01-19 | |c6 |2016-01-20 | |c7 |2016-01-20 | |c8 |2016-01-20 | |c9 |2016-01-20 | |c10 |2016-01-21 | |c11 |2016-01-21 | +-------------+-----------+
my result should be:
+-------------+-----------+ |coupon name |created @ | +-------------+-----------+ |c4 |2016-01-19 | |c5 |2016-01-19 | |c6 |2016-01-20 | |c7 |2016-01-20 | |c8 |2016-01-20 | |c9 |2016-01-20 | |c10 |2016-01-21 | |c11 |2016-01-21 | +-------------+-----------+
i have looked same question couldn't find any.
thanks in advance,
try this:
select t1.`coupon name`, t1.`created at` mytable t1 inner join ( select `created at` mytable group `created at` order `created at` desc limit 3 ) t2 on t1.`created at` = t2.`created at`
the above query uses derived table contains last 3 days of table. can last 3 groups of coupons joining in-line table.
Comments
Post a Comment