在没有GROUP BY的汇总查询中,表达式

时间:2019-04-02 05:54:41

标签: mysql

我的查询在本地服务器上运行良好,但在实时服务器上却出现错误。

我的本​​地服务器版本:10.1.36-MariaDB-mariadb.org二进制分发版

和实时服务器版本:5.7.25-cll-lve-MySQL社区服务器-(GPL)

错误消息:

In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'uzzal_management.employee.id'; this is incompatible with sql_mode=only_full_group_by

查询:

SELECT `employee`.*, 

(SELECT `des_name` FROM `designation` 
WHERE `employee`.`des_id` = `designation`.`id`) AS name, 

(SELECT `dep_name` FROM `department` 
WHERE `employee`.`dep_id` = `department`.`id`) AS dep_name, 

`emp_salary`.`total`, 
`bank_info`.*, 
`addition`.*, 
`deduction`.*, 

(SELECT TRUNCATE((SUM(ABS(( TIME_TO_SEC( TIMEDIFF( `signin_time`, `signout_time` ) ) )))/3600), 1) AS Hours FROM `attendance` 
WHERE (`attendance`.`emp_id`='Gup1410') AND (DATE_FORMAT(`attendance`.`atten_date`, '%m'))=MONTH(CURRENT_DATE())) AS hours_worked,COUNT(*) AS days FROM `employee` 

LEFT JOIN `department` ON `employee`.`dep_id`=`department`.`id` 
LEFT JOIN `addition` ON `employee`.`em_id`=`addition`.`salary_id` 
LEFT JOIN `deduction` ON `employee`.`em_id`=`deduction`.`salary_id` 
LEFT JOIN `bank_info` ON `employee`.`em_id`=`bank_info`.`em_id` 
LEFT JOIN `emp_salary` ON `employee`.`em_id`=`emp_salary`.`emp_id` 

WHERE `employee`.`em_id`='Gup1410'

1 个答案:

答案 0 :(得分:-2)

转到变量并检查sql_mode,您将在其中找到ONLY_FULL_GROUP_BY,将其删除并保存。它会起作用。enter image description here

enter image description here

相关问题