Write a SQL statement to create a simple table Write a SQL statement to create a table named
countries including columns jobs including columns job_id, job_title,
country_id,country_name and region_id. min_salary, max_salary and check whether the
max_salary amount exceeding the upper limit
Create Table countries (
25000.
Country_ID int,
Create Table Jobs (
Country_Name varchar(8000),
job_id int,
Region_ID int
job_title varchar(500),
);
min_salary decimal(6,0),
Write a SQL statement to create a simple table
max_salary decimal (6,0),
countries including columns
country_id,country_name and region_id which check (max_salary<=25000)
is already exists.
);
CREATE TABLE IF NOT EXISTS countries (
Write a SQL statement to create a table named
COUNTRY_ID varchar(2), countries including columns country_id,
country_name and region_id and make sure
COUNTRY_NAME varchar(40),
that no countries except Italy, India and China
REGION_ID decimal(10,0) will be entered in the table.
); CREATE TABLE IF NOT EXISTS countries (
Write a SQL statement to create the structure COUNTRY_ID varchar(2),
of a table dup_countries similar to countries.
COUNTRY_NAME varchar(40)
Create Table countries (
CHECK(COUNTRY_NAME
Country_ID int, IN('Italy','India','China')) ,
Country_Name varchar(8000), REGION_ID decimal(10,0)
Region_ID int );
); Write a SQL statement to create a table named
countries including columns
Create table if not exists dup_countries country_id,country_name and region_id and
Like countries; make sure that no duplicate data against
column country_id will be allowed at the time
Write a SQL statement to create a duplicate of insertion.
copy of countries table including structure and
data by name dup_countries. CREATE TABLE IF NOT EXISTS countries (
CREATE TABLE IF NOT EXISTS dup_countries COUNTRY_ID varchar(2) NOT NULL,
AS SELECT * FROM countries; COUNTRY_NAME varchar(40) NOT NULL,
REGION_ID decimal(10,0) NOT NULL,
UNIQUE(COUNTRY_ID) COUNTRY_NAME varchar(40) DEFAULT NULL,
); REGION_ID decimal(10,0) NOT NULL,
Write a SQL statement to create a table named PRIMARY KEY (COUNTRY_ID,REGION_ID));
jobs including columns job_id, job_title,
min_salary and max_salary, and make sure that,
the default value for job_title is blank and Insert
min_salary is 8000 and max_salary is NULL will
be entered automatically at the time of
insertion if no value assigned for the specified Create Table countries (
columns.
country_id bigint,
Create Table Jobs (
country_name varchar(8000),
job_id int not null unique,
regional_id decimal(6,0)
job_title varchar(300) not null default '',
);
min_salary decimal(6,0) default 8000,
Insert into countries values(1001,'Canada', 6.6);
max_salary decimal(6,0) default null
select * From countries;
);
2. Write a SQL statement to insert one row into
Write a SQL statement to create a table named the table countries against the column
countries including columns country_id, country_id and country_name.
country_name and region_id and make sure
that the country_id column will be a key field Create Table countries (
which will not contain any duplicate data at the country_id bigint,
time of insertion.
country_name varchar(8000),
Create Table countries (
regional_id decimal(6,0)
country_id int not null unique primary key,
);
country_name varchar(8000) not null,
Insert into countries (country_id,
region_id decimal(6,0)not null country_name) values(1001,'Canada');
); Write a SQL statement to create duplicate of
Write a SQL statement to create a table countries table named country_new with all
countries including columns country_id, structure and data.
country_name and region_id and make sure Create Table countries (
that the combination of columns country_id
and region_id will be unique. country_id bigint,
CREATE TABLE IF NOT EXISTS countries ( country_name varchar(8000),
COUNTRY_ID varchar(2) NOT NULL UNIQUE regional_id decimal(6,0)
DEFAULT '',
); Write a SQL statement to insert one row in jobs
table to ensure that no duplicate value will be
Insert into countries (country_id,
entered in the job_id column.
country_name) values(1001,'Canada');
Create table if not exists country_new
As select * from countries;
show columns from country_new;
select * From country_new;
Write a SQL statement to insert 3 rows by a
single insert statement.
Write a SQL statement to insert a record into
Create Table countries ( the table countries to ensure that, a country_id
and region_id combination will be entered once
country_id bigint, in the table. PRIMARY KEY ENSURE NA DAPAT
country_name varchar(8000), KANG MAY MAILAGAY SA KANYA, UNIQUE
PARA DI LANG MAULIT YUNG INPUT.
regional_id decimal(9,0)
);
Insert into countries values(1001,'Canada',66),
(999,'Alabama',00.1),(22,'Taiwan',88.8);
show columns from countries;
select * From countries;
Write a SQL statement insert rows from
country_new table to countries table.
Write a SQL statement to insert records into
Create Table countries ( the table countries to ensure that the
country_id column will not contain any
country_id bigint,
duplicate data and this will be automatically
country_name varchar(8000), incremented and the column country_name will
be filled up by 'N/A' if no value assigned for that
regional_id decimal(9,0)
column. Mag aauto yung number sa country id,
); 501,502,503
Insert into countries values(1001,'Canada',66),
(999,'Alabama',00.1),(22,'Taiwan',88.8);
Create table if not exists countries_new
as select * from countries;
select * From countries_new;
UPDATE INTO PAG IUUPDATE MO YUNG INSERT How can you change "Thomas" into "Michel" in
MO NA DATA SA COLUMN the "LastName" column in the Users table?
Write a SQL statement to change the email UPDATE Users SET LastName = 'Michel' WHERE
column of employees table with 'not available' LastName = 'Thomas'
for all employees.
ALTER
UPDATE employees SET email='not available';
Write a SQL statement to rename the table
Write a SQL statement to change the email and countries to country_new.
commission_pct column of employees table
ALTER TABLE countries RENAME country_new;
with 'not available' and 0.10 for all employees.
DALAWANG COLUMN NA YUNG INUPDATE Write a SQL statement to add a column
region_id to the table locations
UPDATE employees SET email='not available',
ALTER TABLE locations
commission_pct=0.10;
ADD region_id INT;
Write a SQL statement to change the email
column of employees table with 'not available' Write a SQL statement to add a columns ID as
for those employees whose department_id is the first column of the table locations.
80 and gets a commission is less than .20%.
PAPALITAN YUNG EMAIL NG EMPLOYEES NA ALTER TABLE locations
AND DEP ID IS 80 AT COMMISSION AY LESS ADD ID INT FIRST;
THAN .20%
Write a SQL statement to add a column
UPDATE employees region_id after state_province to the table
SET email='not available' locations
WHERE department_id=80 AND ALTER TABLE locations
commission_pct<.20; ADD region_id INT
Write a SQL statement to change the email AFTER state_province;
column of employees table with 'not available'
for those employees who belongs to the Write a SQL statement to drop the column city
'Accounting' department. from the table locations.
UPDATE employees ALTER TABLE locations
SET email='not available' DROP city;
WHERE department_id=( SELECT or query
SELECT department_id Write a query to display the names (first_name,
last_name) using alias name “First Name", "Last
FROM departments Name" Ito pinili mo lang ilabas yung first name
WHERE department_name='Accounting'); and last name columns.
ELECT first_name "First Name", last_name
"Last Name"
FROM employees; Write a query to get the maximum and
minimum salary from employees table. Lalabas
na output is ang pinaka malaking salary and
pinakamaliit pwede mo ding piliin yung max
Write a query to get unique department ID lang or min lang
from employee table. Bale dito iprprint mo lang
SELECT MAX(salary), MIN(salary)
yung unique dep_id ng each department.
FROM employees;
SELECT DISTINCT department_id
Write a query to get the maximum salary of an
FROM employees;
employee working as a Programmer.
Write a query to get the details of all employees
SELECT MAX(salary)
according to first name in descending order. Ito
lalabas siya nan aka alphabetical or increasing FROM employees
SELECT * WHERE job_id = 'IT_PROG';
FROM employees Write a query to get the average salary and
number of employees working the department
ORDER BY first_name DESC;
90.
Write a query to get the employee ID, name
SELECT AVG(salary),count(*)
(first_name, last_name), salary in ascending
order of salary. Lalabas siya na sunod sunod FROM employees
based sa laki ng salary.
WHERE department_id = 90;
SELECT employee_id, first_name, last_name,
salary
Write a query get all first name from employees
FROM employees
table in upper case. Para maprint na naka
ORDER BY salary; capital yung first name
SELECT UPPER(first_name)
Write a query to get the names (first_name, FROM employees;
last_name), salary, PF of all the employees (PF
Write a query to get the first three characters of
is calculated as 15% of salary).
first name of all employees. Para maprint yung
SELECT first_name, last_name, salary, first three character ng name.
salary*.15 PF
SELECT SUBSTRING(first_name,1,3)
FROM employees;
FROM employees;
Write a query to get the total salaries payable
Write a query to calculate 171*214+625.
to employees.
SELECT 171*214+625 Result;
SELECT SUM(salary)
Write a query to get the name (for example
FROM employees;
Ellen Abel, Sundar Ande etc.) of all the
employees from employees table. Ito GROUP BY job_id;
pagsasamahin mo yung First and Last Name
Write a query to get the difference between the
colum sa print out.
highest and lowest salaries
SELECT CONCAT(first_name,' ', last_name)
SELECT MAX(salary) - MIN(salary) DIFFERENCE
'Employee Name'
FROM employees;
FROM employees;
Write a query to find the manager ID and the
Write a query to get the length of the employee
salary of the lowest-paid employee for that
names (first_name, last_name) from employees
manager.
table. Ito nabibilang yung number of letters sa
name niya SELECT manager_id, MIN(salary)
SELECT first_name,last_name, FROM employees
LENGTH(first_name)+LENGTH(last_name)
'Length of Names' WHERE manager_id IS NOT NULL
FROM employees; GROUP BY manager_id
ORDER BY MIN(salary) DESC;
Write a query to check if the first_name fields Write a query to get the average salary for all
of the employees table contains numbers departments employing more than 10
employees
SELECT *
SELECT department_id, AVG(salary), COUNT(*)
FROM employees
FROM employees
WHERE first_name REGEXP '[0-9]';
GROUP BY department_id
Write a query to select first 10 records from a
table. Para maging output lang is yung 10. HAVING COUNT(*) > 10;
SELECT employee_id, first_name Write a query to get the total salary, maximum,
minimum, average salary of employees (job ID
FROM employees LIMIT 10; wise), for department ID 90 only.
Write a query to get monthly salary (round 2 SELECT job_id, SUM(salary), AVG(salary),
decimal places) of all employees. MAX(salary), MIN(salary)
SELECT first_name, last_name, FROM employees
round(salary/12,2) as 'Monthly Salary'
WHERE department_id = '90'
FROM employees;
GROUP BY job_id;
Write a query to get the number of employees
with the same job. Restricting and Sorting data
SELECT job_id, COUNT(*) Write a query to display the name (first_name,
last_name) and salary for all employees whose
FROM employees salary is not in the range $10,000 through
$15,000. Ilalabas niya yung salary pero di na IN (SELECT department_id FROM departments
included yung said range WHERE department_name='IT');
SELECT first_name, last_name, salary Write a query to find the name (first_name,
last_name) and the salary of the employees
FROM employees
who have a higher salary than the employee
WHERE salary NOT BETWEEN 10000 AND whose last_name='Bull'.
15000;
SELECT FIRST_NAME, LAST_NAME, SALARY
Write a query to display the name (first_name,
FROM employees
last_name) and department ID of all employees
in departments 30 or 100 in ascending order. WHERE SALARY >
Write a query to display the first_name of all (SELECT salary FROM employees WHERE
employees who have both "b" and "c" in their last_name = 'Bull');
first name. yung name niya like bruce
Write a query to find the name (first_name,
SELECT first_name last_name) of the employees who are
managers.
FROM employees
SELECT first_name, last_name
WHERE first_name LIKE '%b%'
FROM employees
AND first_name LIKE '%c%';
WHERE (employee_id IN (SELECT manager_id
Write a query to select all record from
FROM employees));
employees where last name in 'BLAKE', 'SCOTT',
'KING' and 'FORD' Write a query to find the name (first_name,
last_name), and salary of the employees whose
SELECT *
salary is greater than the average salary of all
FROM employees departments.
WHERE last_name IN('JONES', 'BLAKE', 'SCOTT', SELECT * FROM employees
'KING', 'FORD');
WHERE salary >
Write a query to display the last name of
ALL(SELECT avg(salary)FROM employees GROUP
employees having 'e' as the third character
BY department_id);
SELECT last_name FROM employees WHERE Write a query to find the name (first_name, last_name) of the
last_name LIKE '__e%'; employees who are not supervisors
Write a query to find the name (first_name, SELECT b.first_name,b.last_name
last_name) of all employees who works in the IT
FROM employees b
department.
WHERE NOT EXISTS (SELECT 'X' FROM
SELECT first_name, last_name
employees a WHERE a.manager_id =
FROM employees b.employee_id);
Write a query to display the employee ID, first name, last name,
WHERE department_id
and department names of all employees.
SELECT employee_id, first_name, last_name,
(SELECT department_name FROM departments d
WHERE e.department_id = d.department_id) department
FROM employees e ORDER BY department;