Reputation: 375
I have
card_type
table in which there iscard_id
isauto_increment
key andcardtpe
isprimary key
. The another table which I have isactivities
table. Thecolumns
in activities table areactivity_id
withauto_increment
key andactivity
column withprimary key
. The third table isactual_alldetails
table. The columns inactual_alldetails
areid
withauto_increment
key and(emp_code,activity_id,card_id)
column withcomposite key
. The fourth table isemployee
table and columns in these table areemp_code
withprimary key
andemp_name
.
When I am trying to execute one of my query:-
SELECT i.*,
d.Date,
a.in_time,
a.out_time,
SEC_TO_TIME(SUM(TIME_TO_SEC(a.out_time))-(TIME_TO_SEC(a.in_time))) AS duration,
c.cardtype,
a.wo,
v.activity,
a.quty,
a.wastage,
a.mcusage,
a.actual_wastage
FROM employee_details i
INNER JOIN actual_alldetails a ON i.emp_code=a.emp_code
INNER JOIN attendance_date d ON d.date_id=a.date_id
INNER JOIN card_type c ON c.card_id=a.card_id
INNER JOIN activities v ON v.activity_id=a.activity_id
WHERE d.Date='2016-01-30'
ORDER BY v.activity;
It show me error like:
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause.
I don't get understand why it show me error like these. Is it because I am doing inner join with one primary key and one composite key?? If my prediction is right then what is the correct query to do these?? Please help me to solve this problem.
Upvotes: 0
Views: 1731
Reputation: 1408
The error message says it:
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause.
you have a select statement which contains an aggregated value SUM(TIME_TO_SEC(a.out_time)
and a non aggregated value TIME_TO_SEC(a.in_time)
I don't know what exactly the result is you are hoping for but you either have to apply an aggregating function to the second value or you have do add a group by as the error message says so it knows what to group on.
For example change the query to this:
SELECT i.*,
d.Date,
a.in_time,
a.out_time,
SEC_TO_TIME(SUM(TIME_TO_SEC(a.out_time))-(TIME_TO_SEC(a.in_time))) AS duration,
c.cardtype,
a.wo,
v.activity,
a.quty,
a.wastage,
a.mcusage,
a.actual_wastage
FROM employee_details i
INNER JOIN actual_alldetails a ON i.emp_code=a.emp_code
INNER JOIN attendance_date d ON d.date_id=a.date_id
INNER JOIN card_type c ON c.card_id=a.card_id
INNER JOIN activities v ON v.activity_id=a.activity_id
WHERE d.Date='2016-01-30'
GROUP BY i.emp_code
ORDER BY v.activity;
I'm guessing at the id value of your employees: i.emp_code
Upvotes: 1
Reputation: 7701
Look closer at this line:
SEC_TO_TIME(SUM(TIME_TO_SEC(a.out_time))-(TIME_TO_SEC(a.in_time))) AS duration,
There is a SUM()
function here that looks very odd and most likely triggers your error message. Try to remove the SUM
.
Upvotes: 0