Query to find employee of the month in year
HI,
Can anyone please help me in writing the following queries on Northwind database.
1.We are going to motivate employees by creating 'Employee of Month' (employee who has made highest sale). Create Employee of Month List for year 1997.
2.We want to know how our products’ sales differ from each month. Get the list product which
we sold the most and which we sold the least in quantity for each month of 1997.
And for the second problem try:
WITH cte
AS (
SELECT OD.ProductID
,SUM(OD.Quantity) AS SoldQty
,datepart(month, O.OrderDate) AS MonthNumber
,datename(month, O.OrderDate) AS [Month Name]
FROM dbo.Orders O
INNER JOIN dbo.[Order Details] OD ON O.OrderID = OD.OrderID
WHERE O.OrderDate >= '19970101'
AND O.OrderDate < '19980101'
GROUP BY datepart(month, O.OrderDate)
,datename(month, O.OrderDate)
,OD.ProductID
,cte1
AS (
SELECT P.ProductName
,P.ProductID
,cte.SoldQty
,cte.MonthNumber
,cte.[Month Name]
,ROW_NUMBER() OVER (
PARTITION BY cte.MonthNumber ORDER BY SoldQty
) AS RnMin
,ROW_NUMBER() OVER (
PARTITION BY cte.MonthNumber ORDER BY SoldQty DESC
) AS RnMax
FROM cte
INNER JOIN dbo.Products P ON cte.ProductID = P.ProductID
SELECT [Month Name]
,MIN(CASE
WHEN RnMin = 1
THEN ProductName
END) AS [Least Sold Product]
,MIN(CASE
WHEN RnMin = 1
THEN SoldQty
END) AS [Least Sold Qty]
,MIN(CASE
WHEN RnMax = 1
THEN ProductName
END) AS [Best Sold Product]
,MIN(CASE
WHEN RnMax = 1
THEN SoldQty
END) AS [Best Sold Qty]
FROM cte1
GROUP BY [MonthNumber]
,[Month Name]
ORDER BY [MonthNumber]
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Similar Messages
-
Query to find Employee Salary Details
Hi,
Could anyone help in writing the query to find employee salary details.
Thanks in advance.This should get you started:
SELECT papf.full_name
,papf.email_address
,ppp.proposed_salary_n salary
FROM per_pay_proposals ppp
,per_all_assignments_f paaf
,per_all_people_f papf
WHERE ppp.assignment_id = paaf.assignment_id
AND paaf.assignment_type = 'E'
AND paaf.primary_flag = 'Y'
AND paaf.person_id = papf.person_id
AND nvl(papf.current_employee_flag, 'N') = 'Y'
AND trunc(sysdate) BETWEEN
ppp.change_date AND ppp.date_to
AND trunc(sysdate) BETWEEN
paaf.effective_start_date AND paaf.effective_end_date
AND trunc(sysdate) BETWEEN
papf.effective_start_date AND papf.effective_end_date; -
SQL select Statement -first day and last day of the month - 1 year from now
Hi,
I need to write a SQL to get the dates in between first day and last day of the month one year from now.
SELECT last_day(add_months(sysdate,12)) as lastday from dual
What could be the Query to get the first day of the month one year from now..
ie ..Sysdate - 3-DEC-2009
Result - 1-DEC-2010
thank youHi,
You can use TRUNC with 2 arguments to get the first DATE in a month, year, quarter, week, hour, minute, ISO year, ...
SELECT TRUNC ( ADD_MONTHS ( SYSDATE
, 12
, 'MONTH'
) AS first_of_month
FROM dual
;The DATE returned will be in the same month, year, quearter, ... as the first argument.
\We convered the last day of the month in [your previous question|http://forums.oracle.com/forums/message.jspa?messageID=3942939#3942939].
At that time, I warded about using LAST_DAY as a cutoff point; TRUNC is a much better way.
For example, to find all appointment_dates in the current month next year:
SELECT *
FROM appointments
WHERE appointment_date >= TRUNC (ADD_MONTHS (SYSDATE, 12), 'MONTH')
AND appointment_date < TRUNC (ADD_MONTHS (SYSDATE, 13), 'MONTH')Note that
the first part of the WHERE clause calls for dates on or equal to the beginning of the 12th month in the future, but
the second part of the WHERE clause calls for dates before, not equal to , the beginning of the 13th month in the future. -
User is unable to appoint an employee from the previous tax year
Hi Experts,
Can anyone resolve this issue please...
User is unable to appoint an employee from the previous tax year ( 01/12/2010), Appointment date 01/12/2010 for an employee Please asist...
Regards
SavOK .... last user insalled software that was not owned by company. Software removed bug solved.
-
How do I query to find out if the MONITORING clause was enabled on a table?
Our customers are currently running Oracle 8.1.7 in the field. I am writing a database schema updater tool that is supposed to examine the schemas and make necessary changes to them.
Recently, the MONITORING clause was added to many of the tables in our schemas. I need to find out if the tables currently have MONITORING enabled.
But, even though the Oracle documentation is very large, again, I cannot find any information about how to determine if MONITORING on a table is on or off.
Any ideas? An SQL query? JDBC metadata?
Tom Harris
Cisco Systems, Inc.What is the output of the following statements on your system?
Remember, table names are stored in caps in the dictionary if not enclosed within double-quotes.
SQL> create table t (x number) ;
Table created.
SQL> select monitoring from user_tables where table_name = 'T' ;
MON
NO
1 row selected.
SQL> alter table t monitoring ;
Table altered.
SQL> select monitoring from user_tables where table_name = 'T' ;
MON
YES
1 row selected.
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production
SQL> -
Problem: query to find employees at one plant for specified year
Problem: how to determine if an employee was working at a specific plant during a specific year using this limited amount of data in a "job changes" table. No matter what I've tried, I keep getting the wrong number of records and it's driving me nuts. I thought this would be a simple query but it's not (for me anyway!) so I need a "clue" to point me in the right direction. Help? :-)
Sample records:
EMPLID PLANT EFF_DATE HIRE_DATE TERM_DATE
123456 23 01-JAN-00 22-MAR-88 NULL
123456 29 30-JUL-02 22-MAR-88 NULL
123456 22 21-AUG-03 22-MAR-88 NULL
456789 29 11-JUL-01 11-JUL-01 NULL
456789 22 30-JUL-03 11-JUL-01 NULLFor example, how do I write the query so that employee 123456 will show up for years 1999 and 2001 in plant 23?Here is an example:
SQL> SELECT * FROM EMP;
EMPLID PLANT EFF_DATE HIRE_DATE TERM_DATE
123456 23 01-JAN-2000 22-MAR-1988
123456 29 30-JUL-2002 22-MAR-1988
123456 22 21-AUG-2003 22-MAR-1988
456789 29 11-JUL-2001 11-JUL-2001
456789 22 30-JUL-2003 11-JUL-2001
5 rows selected.
SQL> SELECT A.EMPLID,A.PLANT,A.EFF_DATE,A.END_DATE FROM
2 (SELECT EMPLID,PLANT,EFF_DATE,LEAD(EFF_DATE,1) OVER(ORDER BY EMPLID,EFF_DATE) -1 END_DATE,
3 HIRE_DATE FROM EMP
4 WHERE EMPLID=123456
5 ORDER BY EMPLID) A
6 WHERE A.EFF_DATE >= TO_DATE('01-JAN-1999','DD-MON-YYYY')
7 AND A.EFF_DATE <= TO_DATE('31-DEC-2001','DD-MON-YYYY')
8 AND TO_DATE('31-DEC-2001','DD-MON-YYYY') <= END_DATE;
EMPLID PLANT EFF_DATE END_DATE
123456 23 01-JAN-2000 29-JUL-2002
1 row selected. -
SQL Query to find cumulative values for a Financial Year
Dear users,
My requirement is to create a SQL query for a table/view where I have day-wise data. I want to find out cumulative values for financial year by giving any date. It should add the values from start of financial year till that date in the financial year.
I think creating a view of such type will post heavy burden on resources since accuimulation will be done for each day upto that day.
ThanksDear users,
My requirement is to create a SQL query for a
table/view where I have day-wise data. I want to
find out cumulative values for financial year by
giving any date. It should add the values from start
of financial year till that date in the financial
year.
I think creating a view of such type will post heavy
burden on resources since accuimulation will be done
for each day upto that day.
ThanksKumar's solution will serve yours purpose but m not agreed
I think creating a view of such type will post heavy
burden on resources since accuimulation will be done
for each day upto that day. Khurram -
Query to find employee annual salary or pay rate for a pay period (Bi-Week)
Hi Guru's,
need your help for finding annual salary or pay rate for pay period for an employee.
I have below query returning some thousand line which I cant understand. Can someone correct the query please.
SELECT ppp.proposed_salary_n salary From per_pay_proposals ppp,apps.per_all_people_f papf,apps.per_all_assignments_f paaf,apps.per_all_people_f papf1 WHERE papf.person_id = paaf.person_id AND paaf.primary_flag = 'Y' AND paaf.assignment_type = 'E' AND paaf.supervisor_id = papf1.person_id AND papf1.current_employee_flag = 'Y'AND papf.business_group_id = paaf.business_group_id AND SYSDATE BETWEEN papf.effective_start_date and papf.effective_end_date AND SYSDATE BETWEEN paaf.effective_start_date AND paaf.effective_end_date AND SYSDATE BETWEEN papf1.effective_start_date AND papf1.effective_end_date AND papf.employee_number='1234';
SALARY
17.4346
16.0846
17.4346
13.78
13.78
15.07
13.78
13.78
13.78
3305.59
14.859
SALARY
5507.25
2731.01
2690.51
13.78
13.35
13.35
1960
4192
17
4927
2525.02
SALARY
2652
13.35
15.07
2686.67
2964
13.78
17.4635
20.4981
16.0846
13.78
17.4635
SALARY
2666.68
13.78
15.07
13.78
16.0846
17.4635
4353.99
4562.51
17.4346
16.0846
6727.41
SALARY
2780.99
20
17.4346
16.0846
2970
2315.01
17.4635
2629.85
14.5705
5635
17.4346
Thanks
SandeepI used table hrpy_rgdir to get sequence number for the given pernr, payroll area and dates.
Using the sequence number, I am calling Function PYXX_READ_PAYROLL_RESULT to extract the payroll results.
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_hrpy_rgdir
FROM hrpy_rgdir
WHERE srtza = 'A'
AND paydt IN sopaydt
AND abkrs IN soabkrs
AND pernr IN sopernr.
LOOP AT it_hrpy_rgdir.
PERFORM get_rt USING it_hrpy_rgdir-pernr it_hrpy_rgdir-seqnr.
ENDLOOP.
*& Form get_rt
* text
* -->PERNR text
* -->SEQNR text
FORM get_rt USING pernr seqnr.
CLEAR: it_payroll_result.
CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
EXPORTING
clusterid = 'RQ'
employeenumber = pernr
sequencenumber = seqnr
CHANGING
payroll_result = it_payroll_result
EXCEPTIONS
illegal_isocode_or_clusterid = 1
error_generating_import = 2
import_mismatch_error = 3
subpool_dir_full = 4
no_read_authority = 5
no_record_found = 6
versions_do_not_match = 7
error_reading_archive = 8
error_reading_relid = 9
OTHERS = 10.
ENDFORM.
For any period, the function module just returns sy-subrc = 6 [no_record_found].
We are on Australian Payroll. Could you please let me know what I might be missing or is there an alternative way of getting the information ?
Thank you -
Hi Friends,
i want to find the week of a month when i pass a date
example : i will pass "7-jun-07" as input
i would like to get "2" as the out put
is there any built in to do so
please suggest me
regards,
Khaderyour query seems to be wrong:
SQL> with c as
2 (select to_date('1-jun-07','dd-mon-yy')+level-1 your_day from dual connect by level<=15
3 )
4 select your_day, to_char(your_day,'day') week_day, case when to_char(your_day,'fmday') = 'sunday'
5 then to_char(to_number(to_char(your_day,'w'))+1)
6 else
7 to_char(your_day,'w') end ushitaki_week_no,
8 to_char(your_day,'iw')-to_char(trunc(your_day,'mm'),'iw')+1 week_no_in_month--for expicit conversion use to_number
9 from c;
YOUR_DAY WEEK_DAY USHITAKI_WEEK_NO WEEK_NO_IN_MONTH
01.06.2007 friday 1 1
02.06.2007 saturday 1 1
03.06.2007 sunday 2 1
04.06.2007 monday 1 2
05.06.2007 tuesday 1 2
06.06.2007 wednesday 1 2
07.06.2007 thursday 1 2
08.06.2007 friday 2 2
09.06.2007 saturday 2 2
10.06.2007 sunday 3 2
11.06.2007 monday 2 3
12.06.2007 tuesday 2 3
13.06.2007 wednesday 2 3
14.06.2007 thursday 2 3
15.06.2007 friday 3 3
15 rows selected
SQL> -
Query to find Employee's Business group name
Hi,
I am new to HRMS module.
I want to find the employee's (from per_all_people_f) business group details.
I found a base table HR_ALL_ORGANIZATION_UNITS, but there are many records in that table with the same business_group_id as that by itself isnt a unique key.
Could some one assist me in finding the link between employees and their BG.
Thanks.the business group details are stored in the table "*PER_BUSINESS_GROUPS_PERF*" So you can use the following clause:
where PER_ALL_PEOPLE_F.BUSINESS_GROUP_ID = PER_BUSINESS_GROUPS_PERF.BUSINESS_GROUP_ID
Good Luck, -
Query to find employee salary details in HRMS
Hi,
Could anyone one provide me the query to get the salary details of an employee.
Thanks.Hi,
Hope this work for you.
SELECT pap.last_name last_name
,pap.first_name first_name
,pap.employee_number employee_id
,hlu2.meaning ethnic_origin
,hlu1.meaning eeo_category
,hlu5.meaning veteran_status
,pap.sex sex
,ROUND(pro.proposed_salary_n, 2) current_salary
,ROUND(pro.proposed_salary_n * ppb.pay_annualization_factor) current_yearly_salary
,pg.NAME grade
,pj.NAME job_name
,pjd.segment3 business_unit
,pjd.segment4 FUNCTION
,pjd.segment5 designation
,pjd.segment2 job_group
,pos.date_start hire_date
,NVL(pos.actual_termination_date, hr_general.end_of_time) termination_date
,hl.location_code LOCATION
,pap.full_name
,pj.job_information3 flsa_code
,hlu4.meaning employment_category_meaning
,pap.effective_start_date p_effective_start_date
,pap.effective_end_date p_effective_end_date
,paa.effective_start_date a_effective_start_date
,paa.effective_end_date a_effective_end_date
,pro.from_change_date s_effective_from_date
,NVL(pro.to_change_date, hr_general.end_of_time) s_effective_to_date
,pap.current_employee_flag
FROM per_all_people_f pap
,per_all_assignments_f paa
,per_periods_of_service pos
,(SELECT pro1.approved
,pro1.assignment_id
,pro1.change_date from_change_date
, pro_next.change_date - 1 to_change_date
,pro1.multiple_components
,pro1.last_change_date
,pro1.proposed_salary_n
,pro1.forced_ranking
,pro1.last_updated_by
,pro1.last_update_date
,pro1.event_id
,pro1.performance_review_id
,pro1.pay_proposal_id
FROM per_pay_proposals pro1
,per_pay_proposals pro_next
WHERE pro1.assignment_id = pro_next.assignment_id(+)
AND pro1.change_date = pro_next.last_change_date(+)) pro
,per_jobs pj
,per_job_definitions pjd
,hr_locations hl
,per_grades pg
,(SELECT *
FROM hr_lookups
WHERE lookup_type = 'US_EEO1_JOB_CATEGORIES') hlu1
,(SELECT *
FROM hr_lookups
WHERE lookup_type = 'US_ETHNIC_GROUP') hlu2
,(SELECT *
FROM hr_lookups
WHERE lookup_type = 'US_EXEMPT_NON_EXEMPT') hlu3
,(SELECT *
FROM hr_lookups
WHERE lookup_type = 'EMP_CAT') hlu4
,(SELECT meaning
,lookup_code
FROM hr_lookups
WHERE lookup_type LIKE 'US_VETERAN_STATUS') hlu5
,per_pay_bases ppb
,(SELECT *
FROM per_addresses
WHERE primary_flag = 'Y'
AND address_type = 'H'
AND ( date_to IS NULL
OR date_to > SYSDATE)) addr
WHERE pap.person_id = paa.person_id
AND paa.assignment_id = pro.assignment_id
AND paa.job_id = pj.job_id
AND paa.location_id = hl.location_id
AND paa.grade_id = pg.grade_id(+)
AND pos.person_id = pap.person_id
AND ppb.pay_basis_id = paa.pay_basis_id
AND pj.job_information1 = hlu1.lookup_code
AND pj.job_definition_id = pjd.job_definition_id
AND pap.per_information1 = hlu2.lookup_code(+)
AND pap.per_information5 = hlu5.lookup_code(+)
AND pj.job_information3 = hlu3.lookup_code(+)
AND paa.employment_category = hlu4.lookup_code
AND addr.person_id(+) = pap.person_id -
Query to find data of each month
hi,
i have 2 table.
1) Order_tb
Name Null? Type
ORDERID NOT NULL NUMBER
CUSTOMERID NUMBER
ORDERDATE DATE
2) Order_d
Name Null? Type
ORDERID NUMBER
PRODUCTID NOT NULL NUMBER
PRODUCTNAME VARCHAR2(20)
SELLINGPRICE NUMBER
i need to find the total find the total selling price for each month in the year 2012 (orderdate).
i have tried using join, but i could not take the data of 2012 particularly. Please help me on this issue.
thank you
Edited by: RSD on Feb 28, 2013 9:18 AMHi,
RSD wrote:
... i have tried using join, but i could not take the data of 2012 particularly. Please help me on this issue.The WHERE clause below is what limits the results to 2012.
SELECT TRUNC (t.orderdate, 'MONTH') AS month
, SUM (d.sellingprice) AS total_sellingprice
FROM order_tb t
JOIN order_d d ON d.orderid = t.orderid
WHERE t.orderdate >= DATE '2012-01-01'
AND t.orderdate < DATE '2013-01-01'
GROUP BY TRUNC (t.orderdate, 'MONTH')
ORDER BY TRUNC (t.orderdate, 'MONTH')
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Simplify the problem. For example, pretend you're only interested in the first 3 or 4 months of 2012; we'll find a solution tht can easily be adapted for 12 (or any other number) of motnhs.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Query using 0calmonth, to input the month range, data incorrect
hi, experts,
I have a query using 0CALMONTH in the filter, restricted the range value ( eg. 2009.01-2009.08 ),
but the data in Bex Analyzer only 2009.08, doest not collect the cube data from 2009.01 to 2009.08.
If restrict the single value (eg, 2009.02), the data is correct.
I tried to restrict the key figure by 0CALMONTH and then tried using variables with an offset but it does not work as input is a month range.
my bw support package13, basis sp12.
thanks in advance,
xwu.this issue solved by myself, there is a non-cumulative Key Figure.
thanks,
xwu. -
Query to find Items in the 'Sales and Marketing' category set.
Hi,
Does any one have the query to view the 'Categories' and 'Items' assigned within those Categories for the 'Sales and Marketing' category set. Or do you know any other way in which I can get the Catalog hierarchy along with the items assigned within the catalog?
Thanks,
hiten
http://india-votes.blogspot.comAnd for the second problem try:
WITH cte
AS (
SELECT OD.ProductID
,SUM(OD.Quantity) AS SoldQty
,datepart(month, O.OrderDate) AS MonthNumber
,datename(month, O.OrderDate) AS [Month Name]
FROM dbo.Orders O
INNER JOIN dbo.[Order Details] OD ON O.OrderID = OD.OrderID
WHERE O.OrderDate >= '19970101'
AND O.OrderDate < '19980101'
GROUP BY datepart(month, O.OrderDate)
,datename(month, O.OrderDate)
,OD.ProductID
,cte1
AS (
SELECT P.ProductName
,P.ProductID
,cte.SoldQty
,cte.MonthNumber
,cte.[Month Name]
,ROW_NUMBER() OVER (
PARTITION BY cte.MonthNumber ORDER BY SoldQty
) AS RnMin
,ROW_NUMBER() OVER (
PARTITION BY cte.MonthNumber ORDER BY SoldQty DESC
) AS RnMax
FROM cte
INNER JOIN dbo.Products P ON cte.ProductID = P.ProductID
SELECT [Month Name]
,MIN(CASE
WHEN RnMin = 1
THEN ProductName
END) AS [Least Sold Product]
,MIN(CASE
WHEN RnMin = 1
THEN SoldQty
END) AS [Least Sold Qty]
,MIN(CASE
WHEN RnMax = 1
THEN ProductName
END) AS [Best Sold Product]
,MIN(CASE
WHEN RnMax = 1
THEN SoldQty
END) AS [Best Sold Qty]
FROM cte1
GROUP BY [MonthNumber]
,[Month Name]
ORDER BY [MonthNumber]
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Query to find employee competence score and rating against each competence
Hi Guys,
I am looking for a query to retrieve the below information -
1. Job competency requirement value ( stored in competency requirement screen)
2. Actual competenct value ( stored in competence profile)
Basically from these two values, we like to figure out the competency gap for the employee.
Appreciate your help!
thanks,
ABany help guru's!!!!
Maybe you are looking for
-
How can I share my iPhoto library with my wife's iPad?
Is it possible to share my iPhoto library (Yosemite) with my wife's iPad? She doesn't have a separate mac, but she does have her own apple ID.
-
Is there away to back up every thing in lightroom. Like FTP settings, printer profiles, develop presets, metadata presets? Basically all of these things that I thougth would be backed up in the catalog but were not. Braden
-
Does anyone know of any issues with photoshop CS4 and Mountain Lion?
Does anyone know of any issues with photoshop CS4 and Mountain Lion?
-
Im trying to find out how to get on my computer it says that i need to re-install <windows root>/system32/hal.d11. dont know how and i pressed f10 to recover my system and it gets to 77 percent and says having trouble extracting files or something li
-
So i was about to download iTunes for Vista 64bit, then i found out that other software comes with it too, such as QuickTime, Bonjour and some kid of Apple's update software, do i really need these extra apps? I am ok with QuickTime but how about the