Dbms SQL Queries
Dbms SQL Queries
Two tables
create table customers ( customer_id int primary key, customer_name varchar,email varchar,phone
int);
create table orders (order_id int primary key, order_date date,total_amount int,customer_id int,
foreign key(customer_id) REFERENCES customers(customer_id));
Given 2 tables ENGINEER and DATA, query the sum of Count of all the engineers
whose Type is FrontEnd.
SELECT SUM(ENGINEER.Count) as A FROM ENGINEER INNER JOIN DATA ON
ENGINEER.ID = DATA.ID WHERE DATA.Type = 'FrontEnd';
Given a table STUDENT, query for all the Names with Class 1 and SubjectCount
greater than 3.
Given a table COUNTRY, query for all the country names with Code NA.
SELECT Name FROM COUNTRY WHERE Code = 'NA';
Given a table STUDY, query for all the attributes, which have marks greater than
80.
SELECT * FROM STUDY WHERE ID IN (SELECT ID FROM STUDY WHERE Marks >
80);
Max salary
FROM employees;
FROM employees
SELECT employee_name
FROM employees
Correlated query
SELECT employee_name
FROM employees e
WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id =
e.department_id);
Count the number of employees in each department and show only those with
more than 5 employees.
FROM employees
GROUP BY department_id
FROM products p
GROUP BY p.product_category;
FROM departments d
FROM employees