SELECT *FROM(SELECT petname,SUM(quantity) as totalFROM pets a NATURAL JOIN sales bGROUP BY petname) xNATURAL JOIN(SELECT MIN(total) as totalFROM(SELECT petname,SUM(quantity) as totalFROM pets a NATURAL JOIN sales bGROUP BY petname)y)z
pgsql-novice by date:
Соглашаюсь с условиями обработки персональных данных