- SELECT entry_date as latest_entry, amount, type
- from rents
- INNER JOIN (
- SELECT MAX(entry_date) AS maxdate
- FROM rents
- WHERE "type" = 'Income'
- GROUP BY YEAR(entry_date), MONTH(entry_date)
- ) x ON rents. entry_date = maxdate
However, I'm struggling to get this working with Analytics. I've tried various ideas with no luck.
Query runs with no results but the Main + Sub-query work fine individually. FYI: the sub-query looks for the latest date by year and month, this is by design, so LAST_DAY function will not work in my case.
- SELECT
- DATE_FORMAT("t1"."entry_date", '%Y-%m-%d') as latest_date,
- "t1"."amount" as amount
- FROM "rents" t1
- JOIN( SELECT date_format(max("t2"."entry_date"), '%Y-%m-%d') as maxdate
- FROM "rents" t2
- WHERE "t2"."type" = 'Income'
- GROUP BY YEAR("t2"."entry_date"),
- MONTH("t2"."entry_date")
- ) x ON DATE_FORMAT("t1"."entry_date", '%Y-%m-%d') = 'maxdate'
I've done various other options in attempts to make this work and even changed the date format to sting from the original table and still no luck. I'm missing something with Analytics.
Thanks in advance.