0% found this document useful (0 votes)
20 views3 pages

Date Task 17-08-24

The document contains a series of SQL queries designed to perform various data retrieval tasks related to employee information, financial transactions, and date calculations. It includes queries for finding the last day of the previous month, determining maximum credit or debit days, calculating age differences among employees, and identifying leap years. Additionally, it provides methods to analyze employee hiring trends by month and print specific date-related information.

Uploaded by

velan sarathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Date Task 17-08-24

The document contains a series of SQL queries designed to perform various data retrieval tasks related to employee information, financial transactions, and date calculations. It includes queries for finding the last day of the previous month, determining maximum credit or debit days, calculating age differences among employees, and identifying leap years. Additionally, it provides methods to analyze employee hiring trends by month and print specific date-related information.

Uploaded by

velan sarathy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1 Find Previous Day Of Last Day Of Previous Month

SELECT Last_Day(ADD_MONTHS(SYSDATE,-1))-1 as Result FROM DUAL;

2 Query To Find In Which Day He Have Maximum Credit Or Debit

With Tab as
(Select Trans_date,SUM(Trans_amount) Max_Trans,Trans_type,
Rank() Over(Partition by Trans_type Order by SUM(Trans_amount) desc) Ranking
from Bank group by Trans_date,Trans_type)
Select Trans_date,Max_Trans,Trans_type from Tab where Ranking=1;

3 Age Difference Between Each Employees For Each Department

With Tab as
(select employee_id,First_name,department_id,Hire_date,
Lag(Hire_date,1,Hire_date) over(partition by department_id order by Hire_date) La
from employees)
select employee_id,First_name,department_id,Hire_date,La,
Months_between(Hire_date,La)/12 Age_Di
from Tab;

4 Find The Highest Age With Respect To Departnent_Id ;

SELECT DEPARTMENT_ID, MIN(HIRE_DATE) MAX_DATE,


ROUND((MONTHS_BETWEEN(SYSDATE,(MIN(HIRE_DATE)))/12),2) HIGHEST_AGE
FROM EMPLOYEES
GROUP BY DEPARTMENT_ID ORDER BY MIN(HIRE_DATE) ASC;

17 Find Age Of Each Employees ;---SAME Q/N

Select Employee_id,First_name,Round((Months_Between(Sysdate,Hire_date)/12),2)
Result from Employees;

6 Number Of Employees Joined In Each Month

With Tab as
(Select Count(Employee_id) CNT,To_Char(Hire_date,'Month') Join_Month,
Rank() Over(Partition by To_Char(Hire_date,'Month') order by
To_Char(Hire_date,'Month') asc) RN
from Employees group by Hire_date)
Select SUM(CNT),Join_Month from Tab group by Join_Month order by Join_Month asc ;

7 Check Whether This Is Leap Year

Select Case When Mod(to_char(SYSDATE,'YYYY'),4)=0 Then 'Leap Year'


Else 'Not a Leap Year' End as Result from Dual;

8 Find Which Years Are Leap Year In Last 20 Years

with Tab as(select (to_char(sysdate,'yyyy')-level)leapyear from dual connect by


level<=20)
select leapyear from Tab where mod(leapyear,4)= 0 ;
9 Age Difference Between Employees;

With Tab as
(select employee_id,First_name,department_id,Hire_date,
Lag(Hire_date,1,Hire_date) over(order by Hire_date) La
from employees)
select employee_id,First_name,department_id,Hire_date,La,
Months_between(Hire_date,La)/12 Age_Di
from Tab;

17 age till today;

Select Employee_id,First_name,Round((Months_Between(Sysdate,Hire_date)/12),2)
Result from Employees;

10 PRINT DAY OF your birthday

Select To_Char((To_Date('29-06-1994','DD-MM-YYYY')),'Day') Result from Dual;

11 PRINT your birthday IN MONTH-dd-YEAR FORMAT

Select (Months_between('29-06-2024','29-06-1994')/12) ||' Year ' ||


(Months_between('29-07-2024','29-06-2024'))|| ' Month ' ||
Round(Months_between(SYSDATE,'29-07-2024')*30)|| ' Days' Age
from Dual;

12 CHECK your birthday IS leap YEAR OR NOT

Select Case When Mod(to_char(To_date('29-06-1994','DD-MM-YYYY'),'YYYY'),4)=0 Then


'Leap Year'
Else 'Not a Leap Year' End as Result from Dual;

13 how many DAYS OLD ARE you?

select Round((Months_between(Sysdate,'29-06-1994')/12)*365) Days_Old from Dual;

14 PRINT exact 10 YEARS BEFORE you bday AND PRINT the DAY

Select To_Char((Add_Months((To_date('29-06-1994','DD-MM-YYYY')),-(10*12))),'DAY')
RESULT from Dual;

19 age difference BETWEEN 08-05-1998 - 10-05-2012

SELECT ROUND((MONTHS_BETWEEN('10-05-2012','08-05-1998')/12),2) RESULT FROM DUAL;

15 PRINT leap YEARS OF 25 YEARS;

with Tab as
(select (to_char(sysdate,'yyyy')+level)yea from dual connect by level<=25)
select yea,case when mod(yea,4)= 0 then ' LEAP YEAR'
when mod(yea,4)<> 0 then ' NOT A LEAP YEAR' end as what_year from Tab;
16 Republic Day of India

SELECT to_char(TO_DATE('26-01-1950', 'DD-MM-YYYY'), 'DAY') AS rep_day FROM dual;

18 april month transaction;


fetch the day of the week the transaction has done ?

Select ID,NAME,TRANS_TYPE,TO_CHAR(TRANS_DATE,'DAY')TRANS_DAY FROM BANK


WHERE TO_CHAR(TRANS_DATE,'MM')='04';

20 print jan to Dec;

select to_char(to_date(level,'MM'),'Month') month


from dual connect by level <= 12;

21 in which month does the company hired the employees most ?

WITH TAB AS
(SELECT COUNT(EMPLOYEE_ID) COUNT_OF_EMP,(TO_CHAR(HIRE_DATE,'MONTH')) HIRE_MONTH,
RANK() OVER(ORDER BY COUNT(TO_CHAR(HIRE_DATE,'MONTH'))DESC)RANKING FROM EMPLOYEES
GROUP BY (TO_CHAR(HIRE_DATE,'MONTH')) ORDER BY COUNT(TO_CHAR(HIRE_DATE,'MONTH'))
DESC)
SELECT COUNT_OF_EMP,HIRE_MONTH FROM TAB WHERE RANKING=1;

You might also like