这是@bluefeet的建议的替代方法,该建议有些相似,但避免了联接(相反,将较高级别的分组应用于已分组的结果集):
SELECt year, MAX(CASE animal WHEN 'kittens' THEN avg_price END) AS "kittens", MAX(CASE animal WHEN 'puppies' THEN avg_price END) AS "puppies"FROM ( SELECt animal, year, COUNT(*) AS cnt, AVG(Price) AS avg_price FROM tab_test GROUP BY animal, year) sWHERe cnt >= 3GROUP BY year;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)