Task - DML Commands - MySQL Restricting and Sorting data #17
Replies: 13 comments
-
Question 1mysql> SELECT first_name, last_name, salary FROM employees WHERE salary NOT BETWEEN 10000 AND 15000 limit 10; Question 2mysql> SELECT first_name, last_name, salary, department_id FROM employees WHERE salary NOT BETWEEN 10000 AND 15000 and department_id IN(30,100) limit 10; Question 3mysql> select first_name, hire_date from employees where substring(hire_date,1,4)=1987; Question 4mysql> select first_name from employees where first_name like '%b%' and first_name like '%c%' limit 10; Question 5mysql> select last_name, job_id, salary from employees where job_id IN('IT_PROG', 'SH_CLERK') and salary NOT IN(4500,10000,15000); Question 6mysql> select last_name from employees where last_name like '__e%'; Question 7mysql> select last_name from employees where last_name like '______'; Question 8mysql> select * from employees where last_name IN ( 'BLAKE', 'SCOTT', 'KING', 'FORD'); |
Beta Was this translation helpful? Give feedback.
-
1. SELECT first_name, last_name, salary FROM employees WHERE salary NOT BETWEEN 10000 AND 15000;
2. SELECT first_name, last_name, salary FROM employees WHERE salary NOT BETWEEN 10000 AND 15000 AND department_id IN
(30, 100);
3. SELECT first_name, last_name, hire_date FROM employees WHERE TO_CHAR(hire_date, 'YYYY') LIKE '%87';
4. SELECT first_name FROM employees WHERE first_name LIKE '%b%' AND first_name LIKE '%c%';
5. SELECT last_name, job_id, salary FROM employees WHERE job_id IN ('IT_PROG', 'SH_CLERK') AND salary NOT IN (4500,10000, 15000);
6. SELECT last_name FROM employees WHERE last_name LIKE '__e%';
7. SELECT last_name FROM employees WHERE last_name LIKE '______';
8. SELECT * FROM employees WHERE last_name IN('JONES', 'BLAKE', 'SCOTT', 'KING', 'FORD');
|
Beta Was this translation helpful? Give feedback.
-
--Q1
select concat(first_name, " ", last_name) as "Name",
salary
from employees
where salary < 10000
OR salary > 15000;
--Q2
select concat(first_name, " ", last_name) as "Name",
salary,
department_id
from employees
where (
salary < 10000
OR salary > 15000
)
AND department_id in (30, 100);
--Q3
select concat(first_name, " ", last_name) as "Name",
hire_date
from employees
where hire_date like "1987%";
--Q4
select first_name
from employees
where first_name like "%b%"
or first_name like "%c%";
--Q5
select last_name,
salary,
job_id
from employees
where job_id in ("IT_PROG", "SH_CLERK")
AND salary not in (4500, 10000, 15000);
--Q6
select last_name
from employees
where last_name like "__e%";
--Q7
select last_name
from employees
where length(last_name) = 3;
--Q8
select *
from employees
where last_name in ("Blake", "Scott", "King", "Ford"); |
Beta Was this translation helpful? Give feedback.
-
select CONCAT(first_name," ",last_name) AS names, salary from employees where salary NOT BETWEEN 10000 and 15000;
select CONCAT(first_name," ",last_name) AS names, salary from employees where salary NOT BETWEEN 10000 and 15000 AND DEPARTMENT_ID IN(30,100);
select CONCAT(first_name," ",last_name) AS names, HIRE_DATE from employees where HIRE_DATE LIKE "1987%";
select first_name from employees where first_name LIKE '%b%' and first_name LIKE'%c%';
select last_name, salary, job_id from employees where job_id in ("IT_PROG","SH_CLERK") AND salary not in (4500,10000,15000);
select last_name from employees where last_name like '__e%';
select last_name from employees where last_name LIKE '______';
select * from employees where last_name IN('BLAKE','SCOTT','KING','FORD'); |
Beta Was this translation helpful? Give feedback.
-
-- Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000.
SELECT concat(first_name, " ", last_name),SALARY
FROM employees
WHERE SALARY NOT BETWEEN 10000 AND 15000;
-- Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000 and are in department 30 or 100.
SELECT concat(first_name, " ", last_name),SALARY
FROM employees
WHERE SALARY NOT BETWEEN 10000 AND 15000 AND DEPARTMENT_ID=30;
-- Write a query to display the name (first_name, last_name) and hire date for all employees who were hired in 1987.
SELECT concat(first_name, " ", last_name) name, HIRE_DATE
FROM employees
WHERE HIRE_DATE LIKE "1987%"
-- Write a query to display the first_name of all employees who have both "b" and "c" in their first name.
SELECT concat(first_name, " ", last_name) AS "name"
FROM employees
WHERE FIRST_NAME LIKE "%B%" OR FIRST_NAME LIKE "%C%"
-- Write a query to display the last name, job, and salary for all employees whose job is that of a Programmer or a Shipping Clerk, and whose salary is not equal to $4,500, $10,000, or $15,000.
select last_name, salary, job_id from employees
where job_id in ("IT_PROG","SH_CLERK") AND salary not in (4500,10000,15000);
-- Write a query to display the last name of employees having 'e' as the third character.
SELECT last_name
FROM employees
WHERE LAST_NAME LIKE "__e%"
-- Write a query to display the last name of employees whose names have exactly 6 characters.
SELECT last_name
FROM employees
WHERE LAST_NAME LIKE "______"
-- Write a query to select all record from employees where last name in 'BLAKE', 'SCOTT', 'KING' and 'FORD'.
SELECT concat(first_name, " ", last_name) AS "name"
FROM employees
WHERE LAST_NAME IN ('BLAKE', 'SCOTT', 'KING' and 'FORD') |
Beta Was this translation helpful? Give feedback.
-
select * from employees;
select first_name, last_name, salary from employees where salary not between 10000 and 15000;
select first_name, last_name, salary, department_id from employees where salary not between 10000 and 15000 and department_id in(30,100);
select first_name, last_name, hire_date from employees where year(hire_date) like 1987;
select first_name from employees where first_name like '%b%' and first_name like '%c%';
select * from jobs;
select e.last_name, j.job_title, e.salary from employees e, jobs j where job_title in ('Programmer', 'Shipping Clerk') and salary not in(4500,10000,15000);
select last_name from employees where last_name like '__e%';
select last_name from employees where last_name like '______';
select * from employees where last_name in ('blake','scott','king','ford'); |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
-- Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000.
SELECT CONCAT(first_name, " ", last_name) as name,
salary
from employees
where salary NOT IN(10000, 15000);
-- Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000 and are in department 30 or 100.
SELECT CONCAT(first_name, " ", last_name) as name,
salary
from employees
where salary NOT IN(10000, 15000)
AND DEPARTMENT_ID = 30
OR DEPARTMENT_ID = 100;
-- or
SELECT CONCAT(first_name, " ", last_name) as name,
salary
from employees
where salary NOT IN(10000, 15000)
AND DEPARTMENT_ID IN(30, 100);
-- Write a query to display the name (first_name, last_name) and hire date for all employees who were hired in 1987.
SELECT CONCAT(first_name, " ", last_name) as name,
hire_date
from employees
where year(HIRE_DATE) LIKE "1987";
-- Write a query to display the first_name of all employees who have both "b" and "c" in their first name.
SELECT first_name
from employees
where first_name LIKE '%b%'
AND first_name LIKE '%c%';
-- Write a query to display the last name, job, and salary for all employees whose job is that of a Programmer or a Shipping Clerk, and whose salary is not equal to $4,500, $10,000, or $15,000.
SELECT last_name,
job_id,
salary
from employees
where job_id = 'IT_PROG'
OR job_id = 'SH_CLERK'
AND salary <> 4500
AND salary <> 10000
AND SALARY <> 15000;
-- or
SELECT last_name,
job_id,
salary
FROM employees
WHERE job_id IN ('IT_PROG', 'SH_CLERK')
AND salary NOT IN (4500, 10000, 15000);
-- Write a query to display the last name of employees having 'e' as the third character.
SELECT last_name
from employees
where LAST_NAME LIKE '__e%';
-- Write a query to display the last name of employees whose names have exactly 6 characters.
SELECT last_name
FROM employees
WHERE last_name LIKE '______';
-- Write a query to select all record from employees where last name in 'BLAKE', 'SCOTT', 'KING' and 'FORD'.
SELECT *
FROM employees
WHERE last_name IN('BLAKE', 'SCOTT', 'KING', 'FORD'); |
Beta Was this translation helpful? Give feedback.
-
1.select CONCAT(FIRST_NAME," ",LAST_NAME) as First_Name, salary from employees where salary NOT IN(10000,15000);
2.select CONCAT(FIRST_NAME," ",LAST_NAME) as First_Name,SALARY,department_id FROM EMPLOYEES WHERE salary NOT IN(10000,15000) AND DEPARTMENT_id in (30,100);
3.select CONCAT(FIRST_NAME," ",LAST_NAME) as First_Name, hire_date from employees where YEAR(HIRE_DATE) like "1987%";
4.SELECT first_name FROM employees WHERE first_name LIKE '%b%' AND first_name LIKE '%c%';
5.select LAST_NAME, JOB_ID, SALARY from EMPLOYEES WHERE JOB_ID IN ("IT_PROG", "ST_CLERK") AND SALARY NOT IN(4500,10000,15000);
6.SELECT LAST_NAME FROM EMPLOYEES WHERE LAST_NAME LIKE "__e%";
7.SELECT LAST_NAME FROM EMPLOYEES WHERE LAST_NAME LIKE "______";
8.SELECT * FROM EMPLOYEES WHERE LAST_NAME IN ("BLAKE","SCOTT","KING","FORD"); |
Beta Was this translation helpful? Give feedback.
-
select * from employees;
select first_name, last_name, salary from employees where salary not between 10000 and 15000;
select first_name, last_name, salary, department_id from employees where salary not between 10000 and 15000 and department_id in(30,100);
select first_name, last_name, hire_date from employees where year(hire_date) like 1987;
select first_name from employees where first_name like '%b%' and first_name like '%c%';
select * from jobs;
select e.last_name, j.job_title, e.salary from employees e, jobs j where job_title in ('Programmer', 'Shipping Clerk') and salary not in(4500,10000,15000);
select last_name from employees where last_name like '__e%';
select last_name from employees where last_name like '______';
select * from employees where last_name in ('blake','scott','king','ford'); |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Hi @akash-coded, since the dumps file is not available, I have written the code to get the data.
SELECT FIRST_NAME, LAST_NAME, SALARY
SELECT FIRST_NAME, LAST_NAME, SALARY
SELECT FIRST_NAME, LAST_NAME, HIRE_DATE
SELECT FIRST_NAME
SELECT e.LAST_NAME, j.JOB_TITLE, e.SALARY
SELECT LAST_NAME
SELECT LAST_NAME
SELECT * |
Beta Was this translation helpful? Give feedback.
-
|
quesion-1 SELECT first_name,last_name,salary FROM employees WHERE salary NOT BETWEEN 10000 AND 15000 question-2 SELECT first_name,last_name,salary FROM employess WHERE salary NOT BETWEEN 10000 AND 15000 AND deparment_id=30 OR 100 question-3 SELECT first_name,last_name FROM employees WHERE hire_date=1987 question-4 SELECT first_name FROM employees WHERE first_name LIKE '%b%' question-5 SELECT last_name,job and salary FROM employees WHERE job_title IN(Programmer,Shipping Clerk) AND salary NOT IN(4500,10000,150000) question-6 SELECT last_name FROM employees WHERE last_name like '__e%'; question-7 SELECT last_name FROM employees WHERE last_name LIKE '______'; question-8 SELECT * FROM employees WHERE last_name IN('BLAKE','SCOTT','KING','FORD'); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Database =
hrDump file: hr.sql
DB Schema
Queries
Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000.
Write a query to display the name (first_name, last_name) and salary for all employees whose salary is not in the range $10,000 through $15,000 and are in department 30 or 100.
Write a query to display the name (first_name, last_name) and hire date for all employees who were hired in 1987.
Write a query to display the first_name of all employees who have both "b" and "c" in their first name.
Write a query to display the last name, job, and salary for all employees whose job is that of a Programmer or a Shipping Clerk, and whose salary is not equal to $4,500, $10,000, or $15,000.
Write a query to display the last name of employees having 'e' as the third character.
Write a query to display the last name of employees whose names have exactly 6 characters.
Write a query to select all record from employees where last name in 'BLAKE', 'SCOTT', 'KING' and 'FORD'.
Beta Was this translation helpful? Give feedback.
All reactions