1. SELECT * FROM employees;
2. SELECT DISTINCT department_id FROM employees;
3. SELECT last_name, salary, commission_pct
FROM employees
WHERE commission_pct = 0.2;
4. SELECT first_name, department_id, salary * 0.15 AS "TA", salary * 0.4 AS "DA", salary * 0.32 AS "HRA", salary * (0.87) + salary AS "GROSS SALARY"
FROM employees;
Certainly, here are your SQL queries separated and explained individually:
5. **Select last names and job IDs of employees with managers (where manager_id is not null)**:
```sql
SELECT last_name, job_id
FROM employees
WHERE manager_id IS NOT NULL;
```
6. **Select specific columns for employees with a non-null commission percentage, ordered by salary**:
```sql
SELECT first_name, last_name, department_id, salary, commission_pct
FROM employees
WHERE commission_pct IS NOT NULL
ORDER BY salary;
```
7. **Select last names and department IDs for employees in departments 30 and 50, ordered by last names**:
```sql
SELECT last_name, department_id
FROM employees
WHERE department_id IN (30, 50)
ORDER BY last_name;
```
8. **Select last names, department IDs, job IDs, and hire dates for employees hired between '20-Feb-1998' and '01-June-1999'**:
```sql
SELECT last_name, department_id, job_id, hire_date
FROM employees
WHERE hire_date >= '20-Feb-1998' AND hire_date < '01-June-1999';
```
9. **Select last names of employees with first names that have "a" as the second character (using the underscore "_" as a wildcard for the first character)**:
```sql
SELECT last_name
FROM employees
WHERE first_name LIKE '_a%';
```
10. **Select last names of employees with both "i" and "o" in their last names**:
```sql
SELECT last_name
FROM employees
WHERE last_name LIKE '%i%' AND last_name LIKE '%o%';
```
11. **Select first names and hire dates of employees hired between '01-Jan-1999' and '31-Dec-1999'**:
```sql
SELECT first_name, hire_date
FROM employees
WHERE hire_date >= '01-Jan-1999' AND hire_date <= '31-Dec-1999';
```
You can run each of these SQL queries separately in your database management system to retrieve the desired results for each query.
23 August 2023 at 22:17
12. **Select first name, last name, salary, and department ID of all employees**:
```sql
SELECT first_name, last_name, salary, department_id
FROM employees;
```
13. **Select only the department IDs of all employees**:
```sql
SELECT department_id
FROM employees;
```
14. **Select distinct department IDs from the employees table**:
```sql
SELECT DISTINCT department_id
FROM employees;
```
15. **Select all columns for employees with a salary greater than 10,000**:
```sql
SELECT *
FROM employees
WHERE salary > 10000;
```
16. **Select all columns for employees with a salary greater than or equal to 10,000**:
```sql
SELECT *
FROM employees
WHERE salary >= 10000;
```
17. **Select all columns for employees with a salary less than 10,000**:
```sql
SELECT *
FROM employees
WHERE salary < 10000;
```
18. **Select all columns for employees with a salary less than or equal to 10,000**:
```sql
SELECT *
FROM employees
WHERE salary <= 10000;
```
19. **Select all columns for employees with a salary not equal to 10,000**:
```sql
SELECT *
FROM employees
WHERE salary <> 10000;
```
20. **Select all columns for employees with a salary equal to 10,000**:
```sql
SELECT *
FROM employees
WHERE salary = 10000;
```
21. **Select all columns for employees with the last name 'King'**:
```sql
SELECT *
FROM employees
WHERE last_name = 'King';
```
21. **Select * from employees where department_id > ANY(90,100)**:
```sql
SELECT *
FROM employees
WHERE department_id > ANY(90,100);
```
22. **Select * from employees where email='SKING'**:
```sql
SELECT *
FROM employees
WHERE email = 'SKING';
```
23. **Select * from employees where salary > any(4000,6000,11000)**:
```sql
SELECT *
FROM employees
WHERE salary > ANY(4000, 6000, 11000);
```
24. **Select * from employees where salary > all(4000,6000,11000)**:
```sql
SELECT *
FROM employees
WHERE salary > ALL(4000, 6000, 11000);
```
25. **Select * from employees where salary in(4100,9500,17000,24000)**:
```sql
SELECT *
FROM employees
WHERE salary IN (4100, 9500, 17000, 24000);
```
26. **Select * from employees where first_name in('Steven','Neena')**:
```sql
SELECT *
FROM employees
WHERE first_name IN ('Steven', 'Neena');
```
27. **Select * from employees where salary between 10000 and 24000**:
```sql
SELECT *
FROM employees
WHERE salary BETWEEN 10000 AND 24000;
```
28. **Select * from employees where hire_date between '12-aug-1987' and '01-jan-2000'**:
```sql
SELECT *
FROM employees
WHERE hire_date BETWEEN '12-aug-1987' AND '01-jan-2000';
```
29. **Select * from employees where first_name like 'Sh%'**:
```sql
SELECT *
FROM employees
WHERE first_name LIKE 'Sh%';
```
30. **Select * from employees where first_name like '%s'**:
```sql
SELECT *
FROM employees
WHERE first_name LIKE '%s';
```
31. **Select * from employees where salary between**:
It appears that this query is incomplete. Please specify the salary range you want to use in the `BETWEEN` clause.
32. **Select * from employees where salary >= 5000 and hire_date <= '17-jun-87'**:
```sql
SELECT *
FROM employees
WHERE salary >= 5000 AND hire_date <= '17-jun-87';
```
33. **Select * from employees where salary >= 5000 and job_id = 'IT_PROG'**:
```sql
SELECT *
FROM employees
WHERE salary >= 5000 AND job_id = 'IT_PROG';
```
34. **Select employee_id, salary + COMMISSION_PCT * salary from employees**:
```sql
SELECT employee_id, salary + (COMMISSION_PCT * salary) AS "Total Earnings"
FROM employees;
```
35. **Select employee_id, first_name, salary * 0.1 as "HRA" from employees**:
```sql
SELECT employee_id, first_name, salary * 0.1 as "HRA"
FROM employees;
```
36. **Select * from employees order by salary desc**:
```sql
SELECT *
FROM employees
ORDER BY salary DESC;
```
37. **Select * from employees order by salary**:
```sql
SELECT *
FROM employees
ORDER BY salary;
```
38. **Select employee_id, first_name, salary * 0.15 as "TA" from employees**:
```sql
SELECT employee_id, first_name, salary * 0.15 as "TA"
FROM employees;
```
28 August 2023 at 03:13
39. **Select * from employees where salary >= 5000 and hire_date >= '01-jan-2000'**:
```sql
SELECT *
FROM employees
WHERE salary >= 5000 AND hire_date >= '01-jan-2000';
```
40. **Select * from employees where salary >= 5000 and job_id = 'SA_MAN'**:
```sql
SELECT *
FROM employees
WHERE salary >= 5000 AND job_id = 'SA_MAN';
```
41. **Select employee_id, first_name, salary + commission_pct * salary from employees**:
```sql
SELECT employee_id, first_name, salary + (commission_pct * salary) AS "Total Earnings"
FROM employees;
```
42. **Select employee_id, first_name, salary, salary * 0.1 as "HRA" from employees**:
```sql
SELECT employee_id, first_name, salary, salary * 0.1 as "HRA"
FROM employees;
```
43. **Select * from employees where hire_date <= '01-jan-2020'**:
```sql
SELECT *
FROM employees
WHERE hire_date <= '01-jan-2020';
```
44. **Select * from employees order by salary**:
```sql
SELECT *
FROM employees
ORDER BY salary;
```
45. **Select * from employees order by salary desc**:
```sql
SELECT *
FROM employees
ORDER BY salary DESC;
```
46. **Select distinct job_id from employees**:
```sql
SELECT DISTINCT job_id
FROM employees;
```
47. **Select employee_id, commission_pct from employees where commission_pct is not null**:
```sql
SELECT employee_id, commission_pct
FROM employees
WHERE commission_pct IS NOT NULL;
```
Aggregate function in sql (04-09-2023)
1. Get the current date and time:
```sql
SELECT SYSDATE FROM DUAL;
```
2. Extract the year from the current date:
```sql
SELECT EXTRACT(YEAR FROM SYSDATE) FROM DUAL;
```
3. Add 12 months to a specific date ('01-jan-2020'):
```sql
SELECT ADD_MONTHS(TO_DATE('01-jan-2020', 'dd-mon-yyyy'), 12) FROM DUAL;
```
4. Get the last day of a specific date ('01-jan-2020'):
```sql
SELECT LAST_DAY(TO_DATE('01-jan-2020', 'dd-mon-yyyy')) FROM DUAL;
```
5. Assuming you have an 'employees' table and want to retrieve the hire date and the last day of '01-jan-2020':
```sql
SELECT hire_date, LAST_DAY(TO_DATE('01-jan-2020', 'dd-mon-yyyy')) FROM employees;
```
6. Calculate the number of months between the current date and '01-jan-2023':
```sql
SELECT MONTHS_BETWEEN(SYSDATE, TO_DATE('01-jan-2023', 'dd-mon-yyyy')) FROM DUAL;
```
1. Get the total number of employees:
```sql
SELECT COUNT(*) FROM employees;
```
2. Get the count of non-null job IDs for employees:
```sql
SELECT COUNT(job_id) FROM employees;
```
3. Get the count of distinct job IDs for employees:
```sql
SELECT COUNT(DISTINCT job_id) FROM employees;
```
4. Find the minimum salary among all employees:
```sql
SELECT MIN(salary) FROM employees;
```
5. Find the maximum salary among all employees:
```sql
SELECT MAX(salary) FROM employees;
```
6. Find the minimum salary for each job ID:
```sql
SELECT job_id, MIN(salary) FROM employees GROUP BY job_id;
```
7. Find the maximum salary for each job ID:
```sql
SELECT job_id, MAX(salary) FROM employees GROUP BY job_id;
```
8. Find the average salary for each department where the department ID is not null:
```sql
SELECT department_id, AVG(salary) FROM employees WHERE department_id IS NOT NULL GROUP BY department_id;
```
Alternative SQL in sql (09-10-2023)
1**
CREATE TABLE Workers(Empno number(4),Name varchar2(122),Job varchar2(55),Mgr number(10),salary number(10));
**
2 **ALTER TABLE Workers
ADD commission number;
**
3** ALTER TABLE Workers
RENAME column job to designation;
**
4 ** ALTER TABLE Workers
DROP column commission;
**
5**
ALTER TABLE Workers
ADD CONSTRAINT not_null
CHECK (Name IS NOT NULL AND Empno IS NOT NULL AND Salary IS NOT NULL);
**
6 ** ALTER TABLE Workers
ADD UNIQUE (Empno);
**
7 ** ALTER TABLE Workers
ADD PRIMARY KEY (Empno);
**
8 **
insert all
into Workers values(69,'Sangram Panda','Programer',234,1200)
into Workers values(68,'Sangbeet Roy','Programer',234,18000)
into Workers values(67,'Sangram Tripathi','Programerhead',231,120000)
into Workers values(66,'Satya narayan misra','jrProgarmer',231,120000)
into Workers values(65,'Soumya Ranjan Panda','developer',234,13000)
select * from dual;
**
9 **
UPDATE Workers
SET Salary = Salary * 1.10;
**
10 **
ALTER TABLE Workers
MODIFY Salary number NULL;
**
Update & Delete (02-11-2023)
1. DROP TABLE Sangram
2. CREATE TABLE Sangram AS SELECT * FROM employees
3. UPDATE Sangram SET JOB_ID='Manager' WHERE First_name='Neena'
4. UPDATE Sangram SET salary=12345 WHERE First_name='Neena'
5. UPDATE Sangram SET Salary=salary+0.1*salary
6. UPDATE Sangram SET JOB_ID='Se_Manager' WHERE First_name='Neena'
7. DELETE FROM Sangram WHERE JOB_ID='Manager'
8. DELETE FROM Sangram WHERE EMPLOYEE_ID IN (101, 105, 107)
9. UPDATE Sangram SET hire_date='15-MAY-2021' WHERE EMPLOYEE_ID=119
10. DELETE FROM Sangram WHERE hire_date>'01-JAN-2021' AND MANAGER_ID IS NOT NULL
11. UPDATE Sangram SET Salary=salary+0.2*salary WHERE JOB_ID LIKE '%man'
12. UPDATE Sangram SET COMMISSION_PCT=0.15*salary WHERE hire_date > '1-JAN-2015'
select sysdate from dual select extract(year from sysdate) from dual select add_month('01-jan-2020',12) from dual select last_day('01-jan-2020') from dual select hire_date, last_day('01-jan-2020') from employees select months_between(sysdate,'01-jan-2023') from dual Agree Gate function select count(*) from employees select count(job_id) from employees for uniq one select count(distinct job_id) from employees select min(salary) from employees select max(salary) from employees select job_id, min(salary) from employees group by job_id select job_id, max(salary) from employees group by job_id select department_id, avg(salary) from employees where department_id is not null group by department_id
select concat(first_name,last_name) as "FULL_NAME" from employees select initcap('wel comw to the wjqn') from dual select substr('ABCDEFG',2,5) from dual select first_name ,length(first_name) from employees select lpad('oracle',100,'*') from dual select rpad('oracel',100,'*') from dual select ltrim('welcome to world','wel') from duaL select Rtrim('welcome to world','wel') from duaL
ASSIGNMENT 4 Q-1 4/9/23 select first_name, CASE When commission_pct >0 then salary*commission_pct else salary*0.4 end as "SPECIAL_ALLOWANCE" from employees order by "SPECIAL_ALLOWANCE"
75 Insert into students1 values(100,'Prakash','11-jan-1995',8732832838,10); Insert into teachers1 values(10,'Sangram Panda','MCA&MAC'); Insert into students1(sno,sname) values(104,'jayPrakash');
insert all into suppliers11 values (20,'Google','Apps') into suppliers11 values (21,'Microsoft','software') into suppliers11 values (22,'Apple','iphone') into suppliers11 values (23,'Web_Angle.com','website') into suppliers11 values (24,'kiit.ac.in','Data') select * from dual;
Update sangram set JOB_ID='Manager' where First_name='Neena'
Update sangram set salary=12345 where First_name='Neena'
Update Sangram SET Salary=salary+0.1 * salary
Update sangram set JOB_ID='Se_Manager' where First_name='Neena'
DELETE Sangram Where JOB_ID='Manager'
DELETE Sangram Where EMPLOYEE_ID in (101,105,107)
Update sangram set hire_date='15-MAY-2021' where EMPLOYEE_ID=119
DELETE Sangram Where hire_date>'01-JAN-2021' AND MANAGER_ID is NOT NULL
Update Sangram SET Salary=salary+0.2 * salary where JOD_ID LIKE '%man'
Update Sangram SET COMMISSION_PCT=0.15 * salary where hire_date > '1-JAN-2015'
select * from Sangram
Update Sangram SET First_name='jHON' where employee_id=105 Update Sangram SET Salary=salary+0.1 * salary job_id="AD_PRES" OR job_id="AD_VP" DELETE Sangram Where JOB_ID="AD_VP" DELETE Sangram Where JOB_ID='AD_PRES' AND HIRE_DATE > '31-DEC-2020'
10 Comments
select sysdate from dual
ReplyDeleteselect extract(year from sysdate) from dual
select add_month('01-jan-2020',12) from dual
select last_day('01-jan-2020') from dual
select hire_date, last_day('01-jan-2020') from employees
select months_between(sysdate,'01-jan-2023') from dual
Agree Gate function
select count(*) from employees
select count(job_id) from employees
for uniq one
select count(distinct job_id) from employees
select min(salary) from employees
select max(salary) from employees
select job_id, min(salary) from employees group by job_id
select job_id, max(salary) from employees group by job_id
select department_id, avg(salary) from employees where department_id is not null group by department_id
select concat(first_name,last_name) as "FULL_NAME" from employees
ReplyDeleteselect initcap('wel comw to the wjqn') from dual
select substr('ABCDEFG',2,5) from dual
select first_name ,length(first_name) from employees
select lpad('oracle',100,'*') from dual
select rpad('oracel',100,'*') from dual
select ltrim('welcome to world','wel') from duaL
select Rtrim('welcome to world','wel') from duaL
ASSIGNMENT 4 Q-1 4/9/23
ReplyDeleteselect first_name, CASE When commission_pct >0 then salary*commission_pct else salary*0.4 end as "SPECIAL_ALLOWANCE" from employees order by "SPECIAL_ALLOWANCE"
select concat(concat('KIIT',' '),'UNIVERSITY')from dual
ReplyDeleteSELECT log(10,400)from dual;
select next_day(sysdate,'friday')from dual
select replace('oracle','rac','v')from dual
select substr('oracle',3,5)from dual
select round(15.19,1)from dual
select round(15.78)from dual
select to_date(sysdate) from dual
select sum(salary)from employees
select sum(salary) as "total_cost" from employees
select To_date('30-SEP-08 10:55 A.M.','DD-MON-YY HH:MI A.M.')as "Fromat_date" from dual
select To_char(HIRE_DATE,'YYYY MONTH, DDDD')AS "TO_CHAR_FUNCTION" FROM employees
select first_name,email, To_char(HIRE_DATE,'fmMONTH/yyyy')AS "TO_CHAR_FUNCTION" FROM employees WHERE JOB_ID ='AD_VP';
select first_name,email, To_char(HIRE_DATE,'fmmonth/YEAR')AS "TO_CHAR_FUNCTION" FROM employees WHERE JOB_ID ='AD_VP';
select first_name, To_char(HIRE_DATE,'fmDdspth "of" Month year fmHH: MI : SS AM')AS "HIREDATE" FROM employees
select first_name,commission_pct,salary+NVL(commission_pct,0)from employees
select first_name,commission_pct,salary,salary*NVL(commission_pct,4)from employees
select concat(first_name,last_name)as "FULL_NAME",job_id, nvl2(commission_pct,'YES','NO')as "commission_Given" from employees
CREATE TABLE Students1(sno number(3),sname varchar(15),dob date,mobile_number number(20),tno number(3));
ReplyDeleteCREATE TABLE teachers1(tno number(3),tname varchar(15),dept varchar(15) DEFAULT 'no dept');
CREATE TABLE suppliers11(supplier_id number(3),name varchar(15),product varchar(15) DEFAULT 'no dept');
CREATE TABLE Persinalinfo(sno number(3),First_name varchar(20),last_name number(15),dob date,gender varchar(8), mobile_number number(20));
75
Insert into students1 values(100,'Prakash','11-jan-1995',8732832838,10);
Insert into teachers1 values(10,'Sangram Panda','MCA&MAC');
Insert into students1(sno,sname) values(104,'jayPrakash');
insert all
into suppliers11 values (20,'Google','Apps')
into suppliers11 values (21,'Microsoft','software')
into suppliers11 values (22,'Apple','iphone')
into suppliers11 values (23,'Web_Angle.com','website')
into suppliers11 values (24,'kiit.ac.in','Data')
select * from dual;
CREATE TABLE Persinalinfo(sno number(3),First_name varchar(20),last_name varchar(20),,dob date,gender varchar(8), mobile_number number(20));
CREATE TABLE Persinalinfoo(sno number(3),First_name varchar(20),last_name varchar(20),dob date,gender varchar(8), mobile_number number(20));
insert all
into Persinalinfoo(sno,First_name,last_name) values (7,'stya','Ranjan')
into Persinalinfoo(sno,First_name) values (8,'saumya')
select * from dual;
select * from students1
select * from teachers1
select * from suppliers11
DROP table sangram
ReplyDeleteCREATE TABLE Sangram AS select * from employees
Update sangram set JOB_ID='Manager' where First_name='Neena'
Update sangram set salary=12345 where First_name='Neena'
Update Sangram SET Salary=salary+0.1 * salary
Update sangram set JOB_ID='Se_Manager' where First_name='Neena'
DELETE Sangram Where JOB_ID='Manager'
DELETE Sangram Where EMPLOYEE_ID in (101,105,107)
Update sangram set hire_date='15-MAY-2021' where EMPLOYEE_ID=119
DELETE Sangram Where hire_date>'01-JAN-2021' AND MANAGER_ID is NOT NULL
Update Sangram SET Salary=salary+0.2 * salary where JOD_ID LIKE '%man'
Update Sangram SET COMMISSION_PCT=0.15 * salary where hire_date > '1-JAN-2015'
select * from Sangram
Update Sangram SET First_name='jHON' where employee_id=105
Update Sangram SET Salary=salary+0.1 * salary job_id="AD_PRES" OR job_id="AD_VP"
DELETE Sangram Where JOB_ID="AD_VP"
DELETE Sangram Where JOB_ID='AD_PRES' AND HIRE_DATE > '31-DEC-2020'
hello khi
ReplyDelete< script>arlet(8);
ReplyDeletejavascript:alert(1);
ReplyDelete< img/src/onerror=prompt(8)>
ReplyDelete