Search
 
SCRIPT & CODE EXAMPLE
 

SQL

Aggregate functions

CREATE TABLE Products
(
    Id INT IDENTITY PRIMARY KEY,
    ProductName NVARCHAR(30) NOT NULL,
    Manufacturer NVARCHAR(20) NOT NULL,
    ProductCount INT DEFAULT 0,
    Price MONEY NOT NULL
);
  
INSERT INTO Products 
VALUES
('iPhone 6', 'Apple', 3, 36000),
('iPhone 6S', 'Apple', 2, 41000),
('iPhone 7', 'Apple', 5, 52000),
('Galaxy S8', 'Samsung', 2, 46000),
('Galaxy S8 Plus', 'Samsung', 1, 56000),
('Mi6', 'Xiaomi', 5, 28000),
('OnePlus 5', 'OnePlus', 6, 38000)

SELECT AVG(Price) AS Average_Price FROM Products
SELECT AVG(Price) FROM Products
WHERE Manufacturer='Apple'
SELECT AVG(Price * ProductCount) FROM Products
SELECT COUNT(Manufacturer) FROM Products
SELECT MIN(Price) FROM Products
SELECT MAX(Price) FROM Products
SELECT SUM(ProductCount) FROM Products
SELECT AVG(DISTINCT ProductCount) AS Average_Price FROM Products
SELECT AVG(ALL ProductCount) AS Average_Price FROM Products
Comment

PREVIOUS NEXT
Code Example
Sql :: column with prefix in sql 
Sql :: Should I use the datetime or timestamp data type in MySQL? 
Sql :: what is mysql 
Sql :: one to many sql 
Sql :: delete join sql server 
Sql :: group by sql 
Sql :: sqlite3.OperationalError: near "7": syntax error 
Sql :: sql decimal with 2 places 
Sql :: ms sql select datetime as date 
Sql :: what is between operator 
Sql :: how do you insert boolean to postgresql 
Sql :: postgres isnull 
Sql :: lumen 
Sql :: sql query examples 
Sql :: sql select column names starting with 
Sql :: mssql xml 
Sql :: mysql isshow 
Sql :: t-sql cheat sheet 
Sql :: allow all local clients (local socket connections) to connect to the kodekloud_db1 
Sql :: vbscript clean up ADODB.Recordset 
Sql :: how to save result of sqlite query in a table 
Sql :: sql create text column limited values 
Sql :: express api ith mysql data 
Sql :: What are the advantages of MySQL when compared with Oracle? 
Sql :: oracle database connection visual studio 2019 
Sql :: postgresql grant alter table to user 
Sql :: sütun güncelleme SQL 
Sql :: mysql get last character of string 
Sql :: ceil upto 2 decimal place mysql 
Sql :: run all sql file from folder postgres command line 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =