Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unknown column 'cleaned.dog_guid' in 'field list'

The goal is to output the average number of tests completed by unique dogs in each Dognition personality dimension.
I already put aliases cleaned in front of dog_guid, but the system shows : 1054, "Unknown column ‘cleaned.dog_guid’ in ‘field list’".
Is there anything I have to revise? Thanks a lot.

SELECT cleaned.dog_guid, cleaned.dimension, AVG(cleaned.numtests) AS Avgtests
FROM (SELECT d.dog_guid AS dogID, d.dimension AS dimension, count(c.created_at) AS numtests
      FROM dogs d JOIN complete_tests c
      ON d.dog_guid = c.dog_guid
      GROUP BY dogID) AS cleaned
GROUP BY cleaned.dog_guid, cleaned.dimension;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You aliased dogs.dog_guid as dogID, in the subquery, so you should refer to dogID in the outer query as well.

SELECT cleaned.dogID, cleaned.dimension, AVG(cleaned.numtests) AS Avgtests
FROM
(
    SELECT d.dog_guid AS dogID, d.dimension,
           COUNT(c.created_at) AS numtests
    FROM dogs d
    INNER JOIN complete_tests c ON d.dog_guid = c.dog_guid
    GROUP BY dogID
) AS cleaned
GROUP BY cleaned.dogID, cleaned.dimension;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading