SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- Hint: use Ctrl+Enter for SQL autocomplete --============================================================================================== -- Table setup --============================================================================================== DROP TABLE IF EXISTS SalesPerson CREATE TABLE SalesPerson ( SalesPersonID INT IDENTITY(1,1) ,SalesPersonName NVARCHAR(200) ,Age INT ,Salary INT ) INSERT INTO SalesPerson ( SalesPersonName ,Age ,Salary ) SELECT 'Abe', 61, 140000 UNION ALL SELECT 'Juan', 34, 70000 UNION ALL SELECT 'Jackie', 45, 51000 UNION ALL SELECT 'Francisco', 28, 65000 UNION ALL SELECT 'Kiran', 37, 75000 UNION ALL SELECT 'Mandy', 52, 100000 --SELECT * FROM SalesPerson sp DROP TABLE IF EXISTS Orders CREATE TABLE Orders ( [OrderID] INT ,OrderDate date ,CustomerID INT ,SalesPersonID INT ,Amount INT ,InsertDate DATETIME2 DEFAULT (GETDATE()) ) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(1,'20190201',4,1,540) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(2,'20170101',4,2,1800) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(3,'20140101',5,3,-460) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(4,'20170101',4,4,2400) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(5,'20130101',3,5,720) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(6,'20170101',3,5,720) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(7,'20190401',1,3,-200) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(8,'20180101',2,3,200) INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount]) VALUES(9,'20170101',1,1,50) -- Inserting duplicate records INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount],InsertDate) VALUES(1,'20190201',4,1,540,'20200101') INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount],InsertDate) VALUES(2,'20170101',4,2,1800,'20200101') INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount],InsertDate) VALUES(3,'20140101',5,3,-460,'20200101') INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount],InsertDate) VALUES(4,'20170101',4,4,2400,'20200101') INSERT INTO Orders([OrderID],OrderDate,[CustomerID],[SalesPersonID],[Amount],InsertDate) VALUES(5,'20130101',3,5,720,'20200101') SELECT COUNT*(*) FROM orders;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear