Stillfinder's avatar

SQLite 'year', 'month' error

Hi,

I have the next method, and it works fine with MySQL, but not with SQLite (when I run my tests). Looks like the root of the problem in 'year' and 'month' in SQLite.

    return static::selectRaw('year(created_at) year, monthname(created_at) month, count(*) published')
        ->groupBy('year', 'month')
        ->orderByRaw('min(created_at) desc')
        ->get()
        ->toArray();

So, should I rewrite this code in some way, or... Actually, I'm not sure about the best solution.

Thank you for any help!

0 likes
2 replies
tomasosho's avatar
return static::selectRaw('year('created_at') year, monthname('created_at') month, count(*) published')
        ->groupBy('year', 'month')
        ->orderByRaw('min(created_at) desc')
        ->get()
        ->toArray();

I don't know what you're tryiing to achieve, but this is a little bit more proper.

Please or to participate in this conversation.