數據庫分組查詢報錯:
1 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'fortress.PartnerSetting.Id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SQL.sql 3 16
數據庫腳本:
select
DISTINCT(AppId),
Id,
MchId,
CompanyId,
PartnerSettingName,
Provider,
ReturnUrl,
NotifyUrl,
RefundNotifyUrl,
Status
from PartnerSetting
where status = 0 GROUP BY AppId;
解決辦法:
1.查詢sql_model腳本:
SELECT @@sql_mode;
查詢出來的是:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
2.修改sql_model
set @@sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
,NO_ENGINE_SUBSTITUTION';
可以再次查詢sql_model,看是否去掉了ONLY_FULL_GROUP_BY