On Mon, Apr 18, 2011 at 08:45:49AM -0700, Danny scratched on the wall: > Hello > > I have a table with a primary key consisting of three columns: Book, > Chapter, Verse. > > I'd like to produce a results set that contains 1 row for each chapter of > each book, showing the total verses in that chapter. > > I know enough SQL to know I can get the total number of verses in a chapter > of a book with > > SELECT COUNT(VERSE) AS TOT_VERSES WHERE BOOK = 1 AND CHAPTER = 1 > > ... but not enough to produce the following ... > > BOOK CHAPTER TOT_VERSES > 1 1 31 > 1 2 22 > 1 3 99 ETC., ETC.
SELECT book, chapter, count(verse) AS total_verses FROM scripture GROUP BY 1, 2; -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable." -- Angela Johnson _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users