2016-01-22 48 views
-1

這是我的示例表:計算平均明智

Title           Author    Rating Publisher    Binding   Dateread Price 
Airframe           Michael Crichton  5 Arrow Books   Paperback   2001-11-10  0 
Prey            Michael Crichton  5 Avon     Paperback   2001-05-11  0 
Congo           Michael Crichton  5 Avon     Paperback   2001-04-10  0 
The Lost World (Jurassic Park, #2)    Michael Crichton  5 Alfred A. Knopf, Inc. Mass Market P... 2001-12-10  0 
Sphere           Michael Crichton  5 Ballantine Books  Paperback   2001-03-11  0 
Timeline           Michael Crichton  4 Arrow Books   Mass Market P... 2001-02-10  0 
Jaya: An Illustrated Retelling of the Mahabarata Devdutt Pattanaik  5 Penguin Global  Paperback   2001-02-11  0 
The Pregnant King        Devdutt Pattanaik  5 Penguin Books India Paperback   2001-03-11  0 
State of Fear         Michael Crichton  5 Avon Books   Paperback   2015-06-11  0 
The Godfather         Mario Puzo    5 NAL     Paperback   2001-12-08  0 

我想計算:

  1. 每個作者的平均評級(最高優先,但不包括那些只有1個作者書,如果兩位作者具有相同的評級,作者有更多的書籍第一位。)

  2. 書年明智的平均評級。 (Highest First)

有沒有人可以幫忙嗎?

+1

'選擇作者,AVG(等級)由author'。其餘的部分作爲練習留給讀者。 –

回答

0

這應該給你所需要的運動...組

Select Avg(Rating), Author 
From BooksDB 
Group by Author 
Order by Avg(Rating) DESC 

Select Avg(Rating), Title 
From BooksDB 
Group by Title 
Order by Avg(Rating) DESC