Skip to main content
Tweeted twitter.com/StackOverflowPT/status/1079346511580938242
adicionou 2 caracteres ao conteúdo
Fonte Link
novic
  • 36,7mil
  • 4
  • 32
  • 70

Olá galera estouEstou com um bugbug que não sei o motivo de tal.

Tenho em meu controllercontroller o seguinte EloquentEloquent:

$balances = BankUser::select(DB::raw('SUM(balance) AS total, 
          created_at, DATE(created_at) AS total_at'))
    ->whereYear('created_at', $year)->whereMonth('created_at', $month)
    >groupBy('total_at')->get();

Que está me gerando o seguinte erro:

SQLSTATE[42000]: Syntax error or access violation: 1055 'db_develop.account_bank_user.created_at' isn't in GROUP BY (SQL: select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from `ut_banks_user` where year(`created_at`) = 2018 and month(`created_at`) = 12 group by `total_at`)

SQLSTATE[42000]: Syntax error or access violation: 1055 'db_develop.account_bank_user.created_at' isn't in GROUP BY (SQL: select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from ut_banks_user where year(created_at) = 2018 and month(created_at) = 12 group by total_at)

Porém se eu copio o SQLSQL que está sendo gerado:

select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from `account_bank_user` where year(`created_at`) = 2018 and month(`created_at`) = 12 group by `total_at`

select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from account_bank_user where year(created_at) = 2018 and month(created_at) = 12 group by total_at``

E executo em meu phpMyAdminPHPMyAdmin ele consulta e trás os registros, o que está faltando no código? :x

Olá galera estou com um bug que não sei o motivo de tal.

Tenho em meu controller o seguinte Eloquent:

$balances = BankUser::select(DB::raw('SUM(balance) AS total, created_at, DATE(created_at) AS total_at'))
    ->whereYear('created_at', $year)->whereMonth('created_at', $month)
    >groupBy('total_at')->get();

Que está me gerando o seguinte erro:

SQLSTATE[42000]: Syntax error or access violation: 1055 'db_develop.account_bank_user.created_at' isn't in GROUP BY (SQL: select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from `ut_banks_user` where year(`created_at`) = 2018 and month(`created_at`) = 12 group by `total_at`)

Porém se eu copio o SQL que está sendo gerado:

select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from `account_bank_user` where year(`created_at`) = 2018 and month(`created_at`) = 12 group by `total_at`

E executo em meu phpMyAdmin ele consulta e trás os registros, o que está faltando no código? :x

Estou com um bug que não sei o motivo de tal.

Tenho em meu controller o seguinte Eloquent:

$balances = BankUser::select(DB::raw('SUM(balance) AS total, 
          created_at, DATE(created_at) AS total_at'))
    ->whereYear('created_at', $year)->whereMonth('created_at', $month)
    >groupBy('total_at')->get();

Que está me gerando o seguinte erro:

SQLSTATE[42000]: Syntax error or access violation: 1055 'db_develop.account_bank_user.created_at' isn't in GROUP BY (SQL: select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from ut_banks_user where year(created_at) = 2018 and month(created_at) = 12 group by total_at)

Porém se eu copio o SQL que está sendo gerado:

select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from account_bank_user where year(created_at) = 2018 and month(created_at) = 12 group by total_at``

E executo em meu PHPMyAdmin ele consulta e trás os registros, o que está faltando no código?

Fonte Link
Tiago Paza
  • 163
  • 1
  • 2
  • 12

Dúvida ao realizar SQL com Eloquent do Laravel

Olá galera estou com um bug que não sei o motivo de tal.

Tenho em meu controller o seguinte Eloquent:

$balances = BankUser::select(DB::raw('SUM(balance) AS total, created_at, DATE(created_at) AS total_at'))
    ->whereYear('created_at', $year)->whereMonth('created_at', $month)
    >groupBy('total_at')->get();

Que está me gerando o seguinte erro:

SQLSTATE[42000]: Syntax error or access violation: 1055 'db_develop.account_bank_user.created_at' isn't in GROUP BY (SQL: select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from `ut_banks_user` where year(`created_at`) = 2018 and month(`created_at`) = 12 group by `total_at`)

Porém se eu copio o SQL que está sendo gerado:

select SUM(balance) AS total, created_at, DATE(created_at) AS total_at from `account_bank_user` where year(`created_at`) = 2018 and month(`created_at`) = 12 group by `total_at`

E executo em meu phpMyAdmin ele consulta e trás os registros, o que está faltando no código? :x