Search
 
SCRIPT & CODE EXAMPLE
 

SQL

Distinct

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 :: SQL Query Orderby Two or More Columns and by number of characters 
Sql :: mysql extract number from string 
Sql :: how to import datadd in sql 
Sql :: configurasi database whmcs 
Sql :: bidirectional outer join sql 
Sql :: mysql sum per week 
Sql :: Manage Database in MySQL 
Sql :: SQL ORDER BY With Multiple Columns 
Sql :: sql to move data from one table to another 
Sql :: pass timestamp in sql quqey of sql server 
Sql :: What is the difference between the LIKE and REGEXP operators in mysql? 
Sql :: Insert and initialize a SQL column with value dependent on another column data 
Sql :: sql saut de ligne 
Sql :: sqlite send a query to a Sqlite DB with Ruby 
Sql :: sql redshift split into first and last name 
Sql :: psql check table fields 
Sql :: jpa generationtype sequence mysql 
Sql :: how to compile a function in oracle 
Sql :: match end of string regex sql 
Sql :: select even number id data from table 
Sql :: count in spqarql 
Sql :: sql 2year 
Sql :: float in sql 
Sql :: subquery in Delete 
Sql :: how to create foreign key in sql server management studio 
Sql :: connecting fastapi to mysql server 
Sql :: how to format tables in sqlplus 
Sql :: sql server isnull function nor working count 
Csharp :: how to write hello world in c# 
Csharp :: how to set a vector 3 variable in csharp 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =