Which SQL statement is used to retrieve data from a database?
Which SQL statement is used to modify existing data in a database?
Consider the following SQL code:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50)
);
INSERT INTO Employees (EmployeeID, FirstName, LastName)
VALUES (1, 'John', 'Doe');
SELECT * FROM Employees;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
INSERT INTO Students (StudentID, Name, Age)
VALUES (1, 'Alice', 20),
(2, 'Bob', 22),
(3, 'Charlie', 21);
SELECT COUNT(*) FROM Students;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
TotalAmount DECIMAL(10, 2),
OrderDate DATE
);
INSERT INTO Orders (OrderID, CustomerID, TotalAmount, OrderDate)
VALUES (1, 101, 100.50, '2023-05-01'),
(2, 102, 200.75, '2023-05-02'),
(3, 103, 150.20, '2023-05-03');
SELECT MAX(TotalAmount) FROM Orders;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50)
);
INSERT INTO Employees (EmployeeID, FirstName, LastName)
VALUES (1, 'John', 'Doe'),
(2, 'Jane', 'Smith'),
(3, 'Alice', 'Johnson');
SELECT FirstName FROM Employees WHERE LastName = 'Smith';
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(50),
UnitPrice DECIMAL(10, 2),
UnitsInStock INT
);
INSERT INTO Products (ProductID, ProductName, UnitPrice, UnitsInStock)
VALUES (1, 'Keyboard', 29.99, 100),
(2, 'Mouse', 19.99, 50),
(3, 'Monitor', 199.99, 10);
SELECT SUM(UnitPrice * UnitsInStock) FROM Products;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
DepartmentID INT
);
INSERT INTO Employees (EmployeeID, FirstName, LastName, DepartmentID)
VALUES (1, 'John', 'Doe', 101),
(2, 'Jane', 'Smith', 102),
(3, 'Alice', 'Johnson', 101);
SELECT DepartmentID, COUNT(*) FROM Employees GROUP BY DepartmentID;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Marks INT
);
INSERT INTO Students (StudentID, Name, Marks)
VALUES (1, 'Alice', 90),
(2, 'Bob', 80),
(3, 'Charlie', 95);
SELECT AVG(Marks) FROM Students;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
TotalAmount DECIMAL(10, 2),
OrderDate DATE
);
INSERT INTO Orders (OrderID, CustomerID, TotalAmount, OrderDate)
VALUES (1, 101, 100.50, '2023-05-01'),
(2, 102, 200.75, '2023-05-02'),
(3, 103, 150.20, '2023-05-03');
SELECT CustomerID, SUM(TotalAmount) FROM Orders GROUP BY CustomerID;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
TotalAmount DECIMAL(10, 2),
OrderDate DATE
);
INSERT INTO Orders (OrderID, CustomerID, TotalAmount, OrderDate)
VALUES (1, 101, 100.50, '2023-05-01'),
(2, 102, 200.75, '2023-05-02'),
(3, 103, 150.20, '2023-05-03');
SELECT CustomerID, SUM(TotalAmount) FROM Orders GROUP BY CustomerID;
What is the output of the above code?
Consider the following SQL code:
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(50),
UnitPrice DECIMAL(10, 2),
UnitsInStock INT
);
INSERT INTO Products (ProductID, ProductName, UnitPrice, UnitsInStock)
VALUES (1, 'Keyboard', 29.99, 100),
(2, 'Mouse', 19.99, 50),
(3, 'Monitor', 199.99, 10);
SELECT ProductName FROM Products ORDER BY UnitPrice DESC;
What is the output of the above code?