TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

SQLite Group by Clause

SQLite Group by Clause with history, features, advantages, installation, commands, syntax, datatypes, operators, expressions, databases, table, crud operations, clauses, like, glob, limit, and clause, advance sqlite

<< Back to SQLITE

SQLite GROUP BY Clause

The SQLite GROUP BY clause is used with SELECT statement to collaborate the same identical elements into groups.

The GROUP BY clause is used with WHERE clause in SELECT statement and precedes the ORDER BY clause.

Syntax:

SELECT column-list
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2....columnN
ORDER BY column1, column2....columnN 

Let's take an example to demonstrate the GROUP BY clause. We have a table named "STUDENT", having the following data:

Sqlite Group by clause 1

Use the GROUP BY query to know the total amount of FEES of each student:

SELECT NAME, SUM(FEES) FROM STUDENT GROUP BY NAME;

Output:

Sqlite Group by clause 2

Now, create some more records in "STUDENT" table using the following INSERT statement:

INSERT INTO STUDENT VALUES (7, 'Ajeet', 27, 'Delhi', 10000.00 );
INSERT INTO STUDENT VALUES (8, 'Mark', 23, 'USA', 5000.00 );
INSERT INTO STUDENT VALUES (9, 'Mark', 23, 'USA', 9000.00 );
Sqlite Group by clause 3

The new updated table has the inserted entries. Now, use the same GROUP BY statement to group-by all the records using NAME column:

SELECT NAME, SUM(FEES) FROM STUDENT GROUP BY NAME ORDER BY NAME;

Output:

Sqlite Group by clause 4

You can use ORDER BY clause along with GROUP BY to arrange the data in ascending or descending order.

SELECT NAME, SUM(FEES) 
FROM STUDENT GROUP BY NAME ORDER BY NAME DESC; 

Output:

Sqlite Group by clause 5




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf