catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Group by not working #635

Closed akahen closed 7 years ago

akahen commented 7 years ago

Hi, the 'GROUP' with aggregate is not working both simple (i.e. count) and more importantly this:

select account, sum(amount), from table group by account

thanks

Andrews54757 commented 7 years ago

@akahen Medoo doesnt support this. Sorry.

I could help you though - but you would have to edit medoo.

catfan commented 7 years ago

This will be supported on next version v1.5. You may check out this branch and try it.

$database->select('table', [
    'account',
    'sum' => Medoo::raw('SUM(<amount>)')
], [
    'GROUP' => 'account'
]);
// SELECT "account", SUM("amount") AS "sum" FROM "table" GROUP BY "account"
akahen commented 7 years ago

That's great, yet that will allow only one sum or aggregate function per select. Why not take the actual column name for the implicit 'as'.

Thanks

On Sep 29, 2017 10:13 PM, Catfan notifications@github.com wrote:

This will be supported on next version v1.5. You may check out this branch and try it.

$database->select('table', [ 'account', 'sum' => Medoo::raw('SUM()') ], [ 'GROUP' => 'account' ]); // SELECT "account", SUM("amount") AS "sum" FROM "table" GROUP BY "account"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/catfan/Medoo/issues/635#issuecomment-333275141, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIUqNBaBezTUBeycSAbw5SaAeLCsJM2Aks5snaOwgaJpZM4Po2ca.

catfan commented 7 years ago

@akahen That's will be a problem and confusing if it become more complex operation.

$database->select('table', [
        'account',
        'sum' => Medoo::raw('SUM(<amount> + <age> + <weight>)')
], [
        'GROUP' => 'account'
]);
akahen commented 7 years ago

hi, will this support an additional aggregate like below? thanks $database->select('table', [ 'account', 'sum' => Medoo::raw('SUM( + + )'), 'sum2' => Medoo::raw('SUM()') ], [ 'GROUP' => 'account' ]);

catfan commented 7 years ago

@akahen definitely

akahen commented 7 years ago

awesome, thanks. can you please update composer as well? thanks