-
Notifications
You must be signed in to change notification settings - Fork 10
The GROUP BY Clause
Siim Kinks edited this page Mar 21, 2017
·
3 revisions
The GROUP BY clause can be used to create unique groups of data, to form aggregations, to remove duplicates and for other reasons.
For instance, you can count all books per author:
| SQL | SqliteMagic |
|---|---|
SELECT AUTHOR_ID, COUNT(*)
FROM BOOK
GROUP BY AUTHOR_ID
|
import static com.siimkinks.sqlitemagic.BookTable.BOOK;
import static com.siimkinks.sqlitemagic.Select.count;
CompiledSelect<Book, Select.SelectN> compiledSelect = Select
.columns(BOOK.AUTHOR_ID, count())
.from(BOOK)
.groupBy(BOOK.AUTHOR_ID)
.compile(); |
Query created above can be used to define a SQL view, for example.