TheDeveloperBlog.com

Home | Contact Us

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

SQLite AVG Function

SQLite AVG Function 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 AVG function

SQLite AVG function is used to retrieve the average value of an expression.

Syntax:

SELECT AVG(aggregate_expression)
FROM tables
[WHERE conditions]; 

Syntax when you use AVG function with GROUP BY clause:

SELECT expression1, expression2, ... expression_n
AVG(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n; 

Example1:

We have a table named "STUDENT", having the following data:

Sqlite Avg function 1

Retrieve the average fees of all students in "STUDENT" table.

SELECT AVG(FEES) AS "Avg Fees"
FROM STUDENT
WHERE ID <= 5; 

Output:

Sqlite Avg function 2

Exampple2: Using DISTINCT clause with AVG function

Retrieve average distinct fees from "STUDENT" table where FEES is greater than 10000.

SELECT AVG(DISTINCT  FEES) AS "Avg Fees"
FROM STUDENT
WHERE FEES > 10000; 

Output:

Sqlite Avg function 3

Example3: Using mathematical formula with AVG function

You can use mathematical formulae to retrieve an average value according to your requirement:

SELECT AVG(FEES / 12) AS "Average Monthly Fees"
FROM STUDENT;

Output:

Sqlite Avg function 4

Example4: Using GROUP BY clause with AVG Function

Retrieve NAME and FEES from the table and GROUP BY the result by AGE:

SELECT NAME, SUM(FEES) AS "Avg Fees by Name"
FROM STUDENT
GROUP BY AGE;

Output:

Sqlite Avg function 5
Next TopicSQLite Count




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