need SQL query suggestion
Hi all
Create the table t_payroll
(number payroll_id)
Insert into t_payroll values (10)
Insert into t_payroll values (20)
Insert into t_payroll values (30)
Insert into t_payroll values (40)
Insert into t_payroll values (50)
commit;
Select * from t_payroll
Output:
Payroll_Id
10
20
30
40
50
Requirement: to spend on payroll id as a parameter, if passed null, then should recover 10,20,30 Payroll id only.
I tried as follows:
Select * from t_payroll
where payroll_id between nvl (& p_payroll_Id, 10) and nvl (& p_payroll_id, 30)
I hope that the work of query above, but it may not work if I need the 10,20,40 payroll Id only.
Please suggest.
Thanks for all your support...
Kind regards
Afzal.
Select * from t_payroll
where (payroll_id = "& p" or (payroll_id in (10,20,30) and '& p' a null value))
----
Ramin Hashimzade
Tags: Database
Similar Questions
-
I need sql query to discover the 5 last update on the back-end oracle
Hi all
I have payable obligation under Oracle, I want to know the last 5 updated to the oracle of in the back end. the table of this 'AP_SYSTEM_PARAMETERS '.
Please suggest me
Kind regards
Patel
Hello
There may be other ways, but for the time being to check this...
Select *.
from (select * from ap_system_parameters by last_update_date desc)
where 1 = 1
and rownum<>
-
SQL query must count number of engaged, end, MEP per month
Hi all
Need Sql query with group by category and count of the PEM attached, terminated, current for every month for the year.
Create table per_all_people_f (person_id varchar2(30), original_date_of_hire date) Create table per_all_assignments_f (person_id varchar2(30), employee_category varchar2(30)) create table per_periods_of_service (person_id varchar2(30), actual_termination_date date) insert into per_all_people_f values(1,to_date('01-FEB-2014','DD-MON-YYYY')); / insert into per_all_people_f values(2,to_date('10-FEB-2014','DD-MON-YYYY')); / insert into per_all_people_f values(3,to_date('10-dec-2013','DD-MON-YYYY')); / insert into per_all_people_f values(4,to_date('10-MAR-2014','DD-MON-YYYY')); / insert into per_all_people_f values(5,to_date('10-dec-2013','DD-MON-YYYY')); / insert into per_all_assignments_f values(1,'ADMIN'); / insert into per_all_assignments_f values(2,'TECH'); / insert into per_all_assignments_f values(3,'TECH'); / insert into per_all_assignments_f values(4,'ADMIN'); / insert into per_all_assignments_f values(5,'ADMIN'); / insert into per_periods_of_service values(3,to_date('05-feb-2014','DD-MON-YYYY')); /
Desired output. "()" are to explain only.
Explanation of columns:
Hired_ADMIN = used category ADMIN
Term _Admin = employee fired from category ADMIN
Current_ADMIN = Total current employees in category ADMIN
Hired_TECH = used in category TECH
Term_TECH = employee fired in category TECH
Current_TECH = Total current employees in category TECH
Month Hired_ADMIN Term_ADMIN Current_ADMIN Hired_TECH Term_TECH Current_TECH Jan-14 0 0 1 0 0 10 (example) Feb-14 2 1 2 0 1 9
Tried the queries below: but not able to get the desired output grouping...
I made different requests for In (Hired), Out (Terminated), need help for current employees by month and grouping as stated above the desired output.
1 request for employees
select in_month,in_month_name , count(decode(employee_category,'ADMIN', person_id)) ADMIN_IN --, count(decode(employee_category,'DOCT', person_id)) DOCT_IN --, count(decode(employee_category,'NURS', person_id)) NURS_IN , count(decode(employee_category, 'TECH', person_id)) TECH_IN from ( select distinct papf.person_id, paaf.employee_category, trunc(papf.original_date_of_hire, 'mm') in_month, decode(userenv('LANG'),'US',to_char(papf.original_date_of_hire, 'Month'),'AR',to_char(papf.original_date_of_hire, 'Month','nls_date_language=Egyptian'),'') in_month_name from per_all_people_f papf ,per_all_assignments_f paaf where papf.person_id = paaf.person_id and Papf.ORIGINAL_DATE_OF_HIRE between to_date('01-JAN-'||:P_YEAR) and to_date('31-dec-'||:P_YEAR) and paaf.employee_category is not null ) group by in_month,in_month_name ORDER BY in_month
2. request for completed employees:
select out_month,out_month_name , count(decode(employee_category,'ADMIN', person_id)) ADMIN_OU --, count(decode(employee_category,'DOCT', person_id)) DOCT_OUT --, count(decode(employee_category,'NURS', person_id)) NURS_OUT , count(decode(employee_category, 'TECH', person_id)) TECH_OUT from ( select distinct papf.person_id, paaf.employee_category, trunc(actual_termination_date,'mm') out_month, decode(userenv('LANG'),'US',to_char(actual_termination_date, 'Month'),'AR',to_char(actual_termination_date, 'Month','nls_date_language=Egyptian'),'') out_month_name from per_all_people_f papf ,per_all_assignments_f paaf ,per_periods_of_service ppos where papf.person_id = paaf.person_id and ppos.person_id = papf.person_id and ppos.actual_termination_date between to_date('01-JAN-'||:P_YEAR) and to_date('31-dec-'||:P_YEAR) and paaf.employee_category is not null ) group by out_month,out_month_name ORDER BY out_month
Pls suggest the sql query for current employees monthly and Hired of the EMP, Terminated the PEM group, according to the current EME Emp_Category.
Please suggest...
Thanks and greetings
Afzal.
Post edited by: 1002933
Try this:
set line 1000 WITH dt AS (SELECT TO_DATE ('01/' || LEVEL || '/' || &p_year, 'dd/mm/yyyy') st_dt FROM DUAL CONNECT BY LEVEL <= 12) SELECT mnth ,hired_admin ,term_admin ,hired_admin - term_admin current_admin ,hired_tech ,term_tech ,hired_tech - term_tech current_tech FROM (SELECT TO_CHAR (st_dt, 'mon-yy') mnth , (SELECT COUNT (*) FROM per_all_people_f h, per_all_assignments_f c WHERE h.person_id = c.person_id AND c.employee_category = 'ADMIN' AND h.original_date_of_hire BETWEEN st_dt AND LAST_DAY (st_dt)) hired_admin , (SELECT COUNT (*) FROM per_all_people_f h ,per_all_assignments_f c ,per_periods_of_service s WHERE h.person_id = c.person_id AND c.employee_category = 'ADMIN' AND h.person_id = s.person_id AND s.actual_termination_date BETWEEN st_dt AND LAST_DAY (st_dt)) term_admin , (SELECT COUNT (*) FROM per_all_people_f h, per_all_assignments_f c WHERE h.person_id = c.person_id AND c.employee_category = 'TECH' AND h.original_date_of_hire BETWEEN st_dt AND LAST_DAY (st_dt)) hired_tech , (SELECT COUNT (*) FROM per_all_people_f h ,per_all_assignments_f c ,per_periods_of_service s WHERE h.person_id = c.person_id AND c.employee_category = 'TECH' AND h.person_id = s.person_id AND s.actual_termination_date BETWEEN st_dt AND LAST_DAY (st_dt)) term_tech FROM dt);
Output:
Enter the value of p_year: 2014
old 1: WITH dt AS (SELECT TO_DATE ('01 /' |)) LEVEL | '/' || & p_year, ' dd/mm/yyyy') st_dt
new 1: WITH dt AS (SELECT TO_DATE ('01 /' |)) LEVEL | '/' || 2014, ' dd/mm/yyyy') st_dt
MNTH HIRED_ADMIN TERM_ADMIN CURRENT_ADMIN HIRED_TECH TERM_TECH CURRENT_TECH
--------------- ----------- ---------- ------------- ---------- ---------- ------------
Jan-14 0 0 0 0 0 0
Feb-14 1 0 1 1 1 0
Mar-14 1 0 1 0 0 0
Apr-14 0 0 0 0 0 0
May-14 0 0 0 0 0 0
Jun-14 0 0 0 0 0 0
Jul-14 0 0 0 0 0 0
Aug-14 0 0 0 0 0 0
Sep-14 0 0 0 0 0 0
Oct-14 0 0 0 0 0 0
Nov-14 0 0 0 0 0 0
MNTH HIRED_ADMIN TERM_ADMIN CURRENT_ADMIN HIRED_TECH TERM_TECH CURRENT_TECH
--------------- ----------- ---------- ------------- ---------- ---------- ------------
Dec-14 0 0 0 0 0 0
12 selected lines.
-
need help with sql query dates
Hello
I have a sql query I need to extract some info between data dates. Where clause in this query is:
WHERE CPD_BUS_UNIT =: ESI_PRM_1
AND CPD_VOUCHER_DATE > =: P_DATE_FROM
AND CPD_VOUCHER_DATE < (: P_DATE_TO + 1).
When I run the query into a toad, I can view the data, but not the execution plan. It gives an error ORA-00932 inconsistent Datatypes.
But when I remove (+ 1): P_DATE_TO, I can c the execution plan and data. The data will be different from the previous.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1 AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM) AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1)
Concerning
-
Hi all
Here is the sql query,
Select papf.employee_number,
-papf.full_name, ppa.effective_date, pp.payroll_name,
PET.element_name,
PIV. Name input_value,
prrv.result_value
-, ppa.payroll_action_id, ppa.time_period_id
Of
Apps.pay_payroll_actions App,
pay_assignment_actions AAP,
pay_payrolls_f pp,
pay_run_results prr,
prrv pay_run_result_values,
pay_input_values_f piv,
animal pay_element_types_f,
Apps.per_all_assignments_f ADP,
Apps.per_all_people_f women's wear
-where ppa.payroll_action_id =: payroll_action_id - give your payroll_action_id
where ppa.payroll_id =: payroll_id
and ppa.payroll_action_id =: payroll_action_id
- and paa.assignment_action_id =: assignment_action_id
and ppa.payroll_action_id = paa.payroll_action_id
and ppa.payroll_id = pp.payroll_id
and paa.assignment_action_id = prr.assignment_action_id
and prr.run_result_id = prrv.run_result_id
and prrv.input_value_id = piv.input_value_id
and piv.element_type_id = pet.element_type_id
and paaf.assignment_id = paa.assignment_id
and paaf.person_id = papf.person_id
and trunc (sysdate) between pp.effective_start_date and pp.effective_end_date
and trunc (sysdate) between pet.effective_start_date and pet.effective_end_date
and trunc (sysdate) between piv.effective_start_date and piv.effective_end_date
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
- and papf.employee_number = '1'
- and ppa.effective_date = July 22, 2014"
and pet.element_name in ('Local Mission allowance', "Compensation of Mission International")
order by 1.3
The result is:
Employee_number Element_Name Input_Value Result_value
1 compensation of Mission international day amount 1000
1 compensation of international Mission Distance days 4
1 value to pay compensation of 1200 International Mission
1 International Mission allowance Start Date 01/01/2014
1 compensation of Mission international day amount 800
1 compensation of international Mission Distance days 10
1 International Mission allowance pay value 2000
1 International Mission allowance Start Date 01/02/2014
1 compensation of Mission local day amount 500
1 compensation of local Mission Distance days 10
1 Mission allowance paid local value 1000
1 compensation of local Mission Start Date 01/11/2014
Desired output:
Employee_number Element_Name Day_Amount Distance_Days Pay_Value Start_Date
1 compensation of international Mission 1000, 1200 4 2014/01/01
1
International Mission allowance 800 10 2000 01/02/2014 1 Mission local compensation 500 10 1000 01/11/2014 Please suggest.
INSERT statement:
TOGETHER TO DEFINE
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Day amount', '1000');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Day amount', '1000');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'number of orders', '196');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'number of orders', '195');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Distance days, 4 ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Distance days, 1 ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
("1', 'International Mission allowance', 'employee Category", "scale of employment medical cities");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
("1', 'International Mission allowance', 'employee Category", "scale of employment medical cities");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Class level', 'G3');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Class level', 'G3');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'class of employment, ' ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'class of employment, ' ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Country of Mission', ' 3003 - Kuwait ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Country of Mission', ' 2004 - Canada ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Mission days, 4' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Mission days, 3' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international","End of Mission Date"' 2014/07/10 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international","End of Mission Date"' 2014/07/19 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international", 'Mission Start Date', ' 2014/07/07 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international", 'Mission Start Date', ' 2014/07/17 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'value of pay', '3000');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'value of pay', '4000');
00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'number of orders', '45');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'number of orders', "456789");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' away days '0' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' Distance days, 1 ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', 'Provided food', 'Y');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'compensation of local Mission","Accommodation provided", 'Y');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'compensation of local Mission","Accommodation provided", 'Y');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', "local Mission allowance", "Mission City", "AL MEDINA");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', "local Mission allowance", "Mission City", "RIYADH");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' Mission days, 4' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' Mission days, 5' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'End of Mission Date' ' 2014/06/16 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'End of Mission Date' ' 2014-06-14 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'Mission Start Date', ' 2014/06/13 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'Mission Start Date', ' 2014/06/10 00:00:00 ');
Thank you very much in advance.
Kind regards
Afzal.
So then... something like this:
SELECT employee_number
element_name
MAX (decode (input_value, 'Day amount', result_value)) AS day_amount
MAX (decode (input_value, 'Days of Distance', result_value)) AS Distance_Days
, MAX (decode (input_value, 'Value of pay', result_value)) AS Pay_Value
MAX (decode (input_value, 'Start Date', result_value)) AS Start_Date
from (SELECT papf.employee_number
pet.element_name
piv.NAME input_value
prrv.result_value
prrv.run_result_id
OF apps.pay_payroll_actions App
pay_assignment_actions PAA
pay_payrolls_f pp
pay_run_results prr
pay_run_result_values prrv
pay_input_values_f piv
pay_element_types_f pet
apps.per_all_assignments_f ADP
apps.per_all_people_f women's wear
-where ppa.payroll_action_id =: payroll_action_id - give your payroll_action_id
WHERE ppa.payroll_id =: payroll_id
AND ppa.payroll_action_id =: payroll_action_id
- and paa.assignment_action_id =: assignment_action_id
AND ppa.payroll_action_id = paa.payroll_action_id
AND ppa.payroll_id = pp.payroll_id
AND paa.assignment_action_id = prr.assignment_action_id
AND prr.run_result_id = prrv.run_result_id
AND prrv.input_value_id = piv.input_value_id
AND piv.element_type_id = pet.element_type_id
AND paaf.assignment_id = paa.assignment_id
AND paaf.person_id = papf.person_id
AND trunc (sysdate) BETWEEN pp.effective_start_date AND pp.effective_end_date
AND trunc (sysdate) BETWEEN pet.effective_start_date AND pet.effective_end_date
AND trunc (sysdate) BETWEEN piv.effective_start_date AND piv.effective_end_date
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
AND pet.element_name IN ('local Mission allowance', 'International Mission'))
GROUP BY employee_number
element_name
run_result_id
;
You should get your desired result.
Roger
-
Hello
I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)
Primary_ID raj_id Raj_number Raj_format
1 raj rajvend 1
2 raj rajvend 1
3 raj rajvendor1 2
4 raj rajvendor1 2
5 raj rajvendor1 2
6 raj rajvendor2 3
I used under SQL to get query output as below, but has not achieved the required result:
Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)
from raj_table by sl_no asc
SL_NO raj_id raj_number raj_format primary_id
1 1 raj rajvendor 1
1 2 raj rajvendor 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 3
I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.
with t as)
Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the
Select option 2, 'raj', 'rajvend', 1 double Union all
Select 3, 'raj', 'rajvendor1', 2 double Union all
Select 4, 'raj', 'rajvendor1', 2 double Union all
Select 5, 'raj', 'rajvendor1', 2 double Union all
Select 6, 'raj', 'rajvendor2', 3 double
)
Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,
t.*
t
order by primary_id
/
PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
---------- ---------- --- ---------- ----------
1 1 raj rajvend 1
1 2 raj rajvend 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 36 selected lines.
SQL >
SY.
-
Hi friends,
Can someone me posts sub queries SQL:
1 need a query to find locked users and name of the table to each scheme.
2. a query need to know the user using tables in each schema.
Thank you
Lazar T
Hello
1. What do you mean under the user table and it is locked?
2 search for locked objects
SELECT a.sid,a.serial#, a.username,c.os_user_name,a.terminal,
b.object_id,substr(b.object_name,1,40) object_name,sysdate
from v$session a, dba_objects b, v$locked_object c
where a.sid = c.session_id
and b.object_id = c.object_id----
Ramin Hashimzde
-
Need a sql query to get several dates in rows
Hi all
I need a query to get the dates of the last 7 days and each dates must be in a line...
but select sysdate double... gives a line...
Output of expexcted
Dates:
October 1, 2013
30 sep-2013
29 sep-2013
28 sep-2013
27 sep-2013
26 sep-2013
Try:
SQL > SELECT sysdate-7 + LEVEL FROM DUAL
2. CONNECT BY LEVEL<=>=>
3 * ORDER BY 1 DESC
SQL > /.
SYSDATE-LEVEL 7 +.
-----------------------------
October 1, 2013 13:04:52
30 - Sep - 2013 13:04:52
29 - Sep - 2013 13:04:52
28 - Sep - 2013 13:04:52
27 - Sep - 2013 13:04:52
26 - Sep - 2013 13:04:52
25 - Sep - 2013 13:04:52
7 selected lines.
-
Hi all
Sorry I can't speak English very well
=======================
I have a table that contains two columns
table name: total_sal
column name: hire_date
column name: salary
table syntax
create table total_sal (hire_date date
number (6.2)) of salary;
_________________________________________
Example of data in table format
hire_date | salary
01/01/2011 | 1000
01/02/2011 | 2000
01/05/2011 | 500
01/09/2011 | 400
I NEED a SQL QUERY to display the table, as in this example
OF | TO|||||||||||| TOTALSALAY
01/01/2011 | 01/02/2011 | 3000
07/05/2011 | 01/09/2011 | 900
|||||||||||||||||||||||||||||||||| 3900/* Formatted on 9/23/2011 10:14:40 AM (QP5 v5.149.1003.31008) */ WITH t AS (SELECT TO_DATE ('1/1/2011', 'mm/dd/yyyy') hire_date, 1000 salary FROM DUAL UNION SELECT TO_DATE ('2/1/2011', 'mm/dd/yyyy'), 2000 FROM DUAL UNION SELECT TO_DATE ('5/1/2011', 'mm/dd/yyyy'), 500 FROM DUAL UNION SELECT TO_DATE ('9/1/2011', 'mm/dd/yyyy'), 400 FROM DUAL) SELECT "From", "To", totalsalary FROM (SELECT hire_date "From", LEAD (hire_date) OVER (ORDER BY hire_date) "To", salary + LEAD (salary) OVER (ORDER BY hire_date) totalsalary, ROW_NUMBER () OVER (ORDER BY hire_date) rn FROM t) WHERE MOD (rn, 2) = 1 UNION ALL SELECT NULL, NULL, SUM (salary) FROM t
From To TOTALSALARY 1/1/2011 2/1/2011 3000 5/1/2011 9/1/2011 900 3900
-
Need to SQL query to filter records by limited rows and certain condition
Hello guru (s).
I need a SQL query for help.
For an example table t1 as below, I want to find the maximum of 5 larger, but there should be no more than 2 name of the same position. The "BOLD" is the response of desire.
Name Position size
N1 P1 5
N2 P2 50
N3 P3 500
N4 P1 6
N5 P2 60
N6 P3 600
N7 P1 7
N8 P2 70
N9 P3 700
Thank you.not tested!
select name,position,size, from (select name,position,size, row_number() over (order by size desc) a_count from (select name,position,size, row_number() over (partition by position order by size desc) a_count from your_table ) where a_count <= 2 ) where a_count <= 5
Concerning
Etbin
-
Need help with PL/SQL query complex
I need help with a query that need access to data from 3 tables. That's what I did
I created 3 tables
CREATE TABLE post_table
(
post_id varchar (20),
datepost DATE,
KEY (post_id) elementary SCHOOL
) ;
CREATE TABLE topic
(
TOPIC_ID varchar (20),
name varchar (20),
PRIMARY KEY (topic_id)
);
CREATE TABLE blogpost_table
(
TOPIC_ID varchar (20),
post_id varchar (20),
PRIMARY KEY (topic_id, post_id);
FOREIGN KEY (topic_id) REFERENCES topic (topic_id) ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES post_table (post_id) ON DELETE CASCADE
);
Now, I inserted a few values in these tables as
INSERT INTO post_table VALUES ('p1', to_date ('2009-09-14 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p2', to_date ('2009-07-18 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p3', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p4', to_date ('2009-03-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p5', to_date ('2009-07-13 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p6', to_date ('2009-06-12 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p7', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO VALUES subject ("t1", "baseball");
INSERT INTO category VALUES ('t2', 'football');
INSERT INTO blogpost_table VALUES ("t1", "p1");
INSERT INTO blogpost_table VALUES ('t1', 'p3');
INSERT INTO blogpost_table VALUES ("t1", "p4");
INSERT INTO blogpost_table VALUES ('t1', 'p5');
INSERT INTO blogpost_table VALUES ('t2', 'p2');
INSERT INTO blogpost_table VALUES ('t2', 'p6');
INSERT INTO blogpost_table VALUES ("t2", "p7");
I'm launching SQL queries on the table in this topic.
I want to write a SQL query that returns me the name of a topic (s) and the number of blog_post (s) associated with the topic in descending order of the number of blog posts created in July.
Can someone please help me to write this query?
Thank you
Published by: user11994430 on October 9, 2009 07:24Thanks for the test of the configuration!
SQL>SELECT t.NAME, COUNT(*) 2 FROM topic t, blogpost_table b, post_table p 3 WHERE b.topic_id = t.topic_id 4 AND p.post_id = b.post_id 5 AND p.datepost >= DATE '2009-07-01' 6 AND p.datepost < DATE '2009-08-01' 7 GROUP BY t.NAME 8 ORDER BY COUNT(*) desc; NAME COUNT(*) -------------------- ---------- baseball 2 soccer 2
HTH, Urs
-
I need a query that returns the average amount of characters from text colum in MS SQL.
I need a query that returns the average amount of characters from text colum in MS SQL.
Could someone show me how?Sorting, I need of the
DATALENGTH
function
-
Need help to reduce the cost of my sql Query below 100 to optimize.
Can you please suggest how to reduce the COST of my SQL query? Is it possible to get the < 100 COST?
My goal:
------------------------
To recover the data of length (a column is in normalised_event: table) corresponding to each type of call (which is to extract the column rc.abbreviation in reference_code: table) in a given range of dates. So I wrote the following as SQL below:
------------------------------------------------------------------------------------------------------------------
Select nvl (sum (round(ne.duration/60,3)), 0), rc.abbreviation
Since the rc reference_code, normalised_event not
where to_char (rc.reference_code) = ne.full_path
and rc.reference_type_id = 505002 AND
trunc (don't. CHARGE_START_DATE) between trunc (to_date (January 1, 2008 "," dd-mm-yyyy hh24:mi:ss'))))
and trunc (to_date (January 1, 2009 "," dd-mm-yyyy hh24:mi:ss'))))
Rc.abbreviation group
-----------------------------------------------------------------------------------------------------------------
IAM using Toad Software which is taken in charge by oracle 9i.
Explain the plan above query is:
explain plan
Set statement_id = "mp01" for
Select nvl (sum (round(ne.duration/60,3)), 0), rc.abbreviation
Since the rc reference_code, normalised_event not
where to_char (rc.reference_code) = ne.full_path
and rc.reference_type_id = 505002 AND
trunc (don't. CHARGE_START_DATE) between trunc (to_date (January 1, 2008 "," dd-mm-yyyy hh24:mi:ss'))))
and trunc (to_date (January 1, 2009 "," dd-mm-yyyy hh24:mi:ss'))))
Rc.abbreviation group
Select LPad (' ', 2 *(Level-1)). Level | '.' || NVL (position 0). ' ' ||
Operation | ' ' || Options of | ' ' || Object_name | ' ' ||
Object_type | ' ' || Decode (id, 0, Statement_Id |) "Cost = ' | Position)
"Query plan.
From Plan_Table
Start with id = 0 and Statement_Id = 'mp01 ".
Connect Id Parent_Id = prior
And Statement_Id = 'mp01 ";
---------------------------Query Plan explained is----------------------------------------------------------
1.555 INSTRUCTION SELECT mp01 cost = 555
2.1 TYPE GROUP
3.1 FILTER
4.1 HASH JOIN
5.1 TABLE ACCESS BY INDEX ROWID REFERENCE_CODE
6.1 INDEX RANGE SCAN NON-UNIQUE I_REFERENCE_CODE_REF_TYPE
5.2 PARTITION RANGE ALL THE
6.1 TABLE ACCESS FULL NORMALISED_EVENT
-Automatic tracking of the SQl query is:.
recursive calls - 0
DB block gets - 0
compatible gets - 174
physical reads - 0
size - 104
Parse count (hard) - 0
Parse count (chess) - 0
run the County - 2
bytes sent via SQL * Net to dblink - 0
bytes received via SQL * Net from dblink - 0I was wrong. Once again, this shows how it is dangerous to assume (I assumed that FBI was new in 10g because it is when I used them), and the power of the community to ensure that accurate information is provided.
John
-
need to customize SQL query verification
Friends,
I need to create a custom sql query. Please see the following scenarios:
I want to audit all users who are successfully and unsuccessfully to logon to my oracle database. Tahts why I enbale 2 following options:
SQL > session audit every time that successful;
Verification succeeded.
SQL > noaudit session each time it fails.
Verification succeeded.
And I found all the users using the following sql query:
"Select username, to_char (timestamp," MM/DD/YY HH24 ' ") Timestamp, obj_name, returncode, action_name of."
"dba_audit_trail where action_name in ('LOGIN', 'LOGOUT') order by timestamp desc '.
USERNAME TIMESTAMP OBJ_NAME RETURN_CODE ACTION_NAME
-------- --------- -------- ------------- -----------
RIPON 14-12-08 11:51 0 LOGON
SHIPON 14-12-08 11:50 1017 LOGON
RIPON 14-12-08 11:50 1017 LOGON
Here, return_code = 1017 means the user cannot successfully loged on
and, return_code = 0 the average user can successfully connected
Now, I want to custom to the query that is readable to others easily. As
I want to add a column, which meets the follwing If condition.
Return_code = 0, then the column is 'USER CORRECTLY CONNECTED ON' and
If return_code = 1017, then the column displays "USER NOT CORRECTLY CONNECTED ON".
can someone please help with this?
Edited by: shipon_97 14 December 2008 13:28A CASE statement is probably the easiest option
select username, to_char(timestamp,'MM/DD/YY HH24:MI') Timestamp, obj_name, returncode, action_name, (CASE WHEN return_code = 0 THEN 'User logged in successfully' WHEN return_code = 1017 THEN 'User specified an invalid password' ELSE 'User failed to log in for some other reason' END) reason_desc from dba_audit_trail where action_name in ('LOGON','LOGOFF') order by timestamp desc
Note that any nonzero return code indicates a failed to connect. ORA-01017 indicates an invalid user name or password, which is probably the most common error.
Justin
-
Need for SQL query to get the result.
Region
Month Trx type Summary of the resolution AMERICAS -13 may Adjustments Fix EMEA -13 may Adjustments Incorrect AMERICAS -13 may Credit memo Incorrect EMEA -13 may Invoice Fix AMERICAS -13 may Credit memo Fix OFD -13 may Adjustments Fix AMERICAS -13 may Invoice Incorrect DVL -13 may Adjustments Fix DVL -13 may Adjustments Fix OFD -13 may Adjustments Fix Above my Table and here is the result required. Similarly for other regions as well. Can someone help me with the SQL query?
Region Summary of the resolution Setting Credit memo Invoice Total general AMERICAS Fix 1 1 2 Incorrect 0 1 1 2 Like this?
SQL > select * from transaction_audit;
MTH TRX_TYPE REGION BOARD
-------- ------ ----------- ---------
AMERICAS-13 may SETTINGS CORRECT
EMEA-13 may INCORRECT ADJUSTMENT
AMERICAS-13 may CREDIT MEMO INCORRECT
EMEA-13 may INVOICE CORRECT
AMERICAS-13 may CREDIT MEMO CORRECT
OFD-13 may SETTINGS CORRECT
AMERICAS-13 may INVOICE INCORRECTE
LAD-13 may SETTINGS CORRECT
LAD-13 may SETTINGS CORRECT
OFD-13 may SETTINGS CORRECT10 selected lines.
SQL > select region
2, resolution_summary
3, count (decode (trx_type, "ADJUSTMENTS", trx_type)) adjustments
4, County (decode (trx_type, 'HAVING', trx_type)) credit_memo
5, County (decode (trx_type, "BILL", trx_type)) Bill
transaction_audit 6
Group 7
8 by region
9, resolution_summary
10 Decree
11 by region
12, resolution_summary
13.REGION TAKE ADJUSTMENTS CREDIT_MEMO INVOICE
-------- --------- ----------- ----------- ----------
CORRECT THE AMERICAS 1 1 0
0 1 1 INCORRECT AMERICAS
EMEA CORRECT 0 0 1
INCORRECT EMEA 1 0 0
DAL ADDRESS 2 0 0
OFD CORRECT 2 0 06 selected lines.
SQL >
Maybe you are looking for
-
Satellite Pro P300 - 13 M - how to replace the network card?
Hello I have the Satellite Pro P300 - 13M. My sister fell on my UTP cable and so he was taken out by force and because of that "holding-pings" on the front of the port are bent or broken, so whenever I put in a cable with traction slightess or accide
-
Can I update the graphics card for my laptop
Hi guys I use a laptop 650 hp whose CPU is intel core i3-2328Mand including the clock speed is 2.20 GHz, I have improved the capacity of memory up to 4 GB. The laptop is working perfectely and I can play games like fifa 14 and nba 2 k 13 without any
-
Is what camcorder compatible with Windows Movie Maker on Vista Home Premium?
I'm in a bit of a dead end. I have to make and edit a film which is mostly clips stored in Windows Movie Maker on my old computer which has VISTA Home Premium/64 bit. In most old clips (that are compatible), I have to shoot some new images. My rece
-
WRTG54S to connect to the network, but not internet
I have a WRTG54S and Mediacom 12mbps. My router worked fine on my old laptop (a Dell Vista), he was sitting in a box for about 6 months and now that I have a new (Sony running 7) I can connect to my network, but not internet. I have updated the firmw
-
MDS Http POST packet size restriction?
Hello I have a problem with my application and a device connected to a BES for applications (MDS_4.1.7.16) I have this code example: connection = (HttpConnection) Connector.open(this.url,Connector.READ_WRITE,true); connection.setRequestMethod(HttpCon