Need help in the sql query
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
Tags: Database
Similar Questions
-
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.
-
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 am trying to write the SQL for a single recordset.
I have a table with all the info from the standard article and an item_colorID.
I have a table with 2 columns, item_colorID and color_ID color_lookup
I have a table with 2 columns, color_ID colors and color
I want to join the tables and filter it so that a repeat region shows dynamic data by the name of article, thumb, description, price
and also a dynamic list/menu populated by color
filtered so that each element is in the list/menu only available element colors.
I have tried different variations of this sql
SELECT * items INNER JOIN color_lookup ON color_lookup.item_colorID = items.item_colorID INNER JOIN colors ON colors.color_ID = color_lookup.color_ID WHERE items.itemCatID = 3 ORDER BY items.itemName
but the list/menu shows each color choice, multiplied by the number of items in this color
That is to say white will show 80 + times.
Thanks for your help,
Jim balthrop
Hi JB, I think I understand the situation, but of course, I'm not familiar with the interface of the cart software you are using. It seems that you will not be able to use the choice "research from the recordset" because the color is a different Recordset. You can't really understand the color in the main recordset because it would cause the main repeating region show the item once for each available color, which is not what you want.
I also see that the drop-down color is in its own form. If you have placed this process in the main form, would be the behavior recoginize it and treat it differently? In other words, the cart accepts entry options outside the main form element it uses:
I don't know that the shopping cart software contains other methods to add to the cart you can be forced to use.
What shopping cart software are you helping? They have a forum which you could get more targeted assistance?
-
Need help with the RESEARCH QUERY
Hello
I have the follwing query to search in my table.
If the search box is empty and I click to perform a search, all the elements of the array are listed.
How can I change the following query so if: P1_REPORT_SEARCH is null, I have no results.
Thank you
Roseline
SELECT "RDO"."ID",LPAD(NOD, 4, '0') as NOD,"IDD","TIT","TIC", '- - -' AS "DISQUE" ,'- - -' AS "ELEMENT" from "REGDOSSIERS" "RDO" where ( TRANSLATE ( UPPER ("TIT") , 'ÀÂÉÈÊÎÔÛÙÜ' , 'AAEEEIOUUU' ) like '%' || TRANSLATE ( UPPER (:P1_REPORT_SEARCH) , 'ÀÂÉÈÊÎÔÛÙÜ' , 'AAEEEIOUUU' ) || '%' )
Hello
Try
SELECT "RDO"."ID",LPAD(NOD, 4, '0') as NOD,"IDD","TIT","TIC", '- - -' AS "DISQUE" ,'- - -' AS "ELEMENT" from "REGDOSSIERS" "RDO" where ( TRANSLATE ( UPPER ("TIT") , 'ÀÂÉÈÊÎÔÛÙÜ' , 'AAEEEIOUUU' ) like '%' || TRANSLATE ( UPPER (:P1_REPORT_SEARCH) , 'ÀÂÉÈÊÎÔÛÙÜ' , 'AAEEEIOUUU' ) || '%' ) AND :P1_REPORT_SEARCH IS NOT NULL
BR, Jari
-
Hello
It's my first table REPORT
report as)
Select 'vendor_1' vendor, to_date('1/1/2012','DD/MM/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 110 as cost of double union all
Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 120 as cost of double union all
Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 130 as cost of double union all
Select 'vendor_1' vendor, to_date('1/4/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 140 as cost of double union all
Select 'vendor_1' vendor, to_date('1/10/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" element, 200as cost of double union all
Select 'vendor_1' vendor, to_date('1/23/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" as point 0 as the cost of dual union all
Select 'vendor_1' vendor, to_date('1/6/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 160 as cost of double union all
Select 'vendor_1' vendor, to_date('1/7/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 170 as cost of double union all
Select 'vendor_1' vendor, to_date('1/8/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 180 as cost of double union all
Select 'vendor_1' vendor, to_date('1/9/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 190 as cost of double union all
Select 'vendor_1' vendor, to_date('1/20/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 300 as cost of double)
IT'S MY SECOND TABLE: TEMP_WEEK
WITH temp_week (s)
SELECT January 1, 2012 to 07/01/2012 ' AS the week of all the double union
SELECT August 1, 2012 to 14/01/2012 ' AS the week of all the double union
January 15, 2012 to 21/01/2012 ' AS the week of all the double union
SELECT January 22, 2012 to 28/01/2012 ' AS the week of all the double union
(SELECT 29 January 2012 to 31/01/2012 ' WEEK of double)
To find weekly sales that I wrote query below:
SELECT week, supplier, customer, SUM (cost)
(SELECT week, supplier, customer, TOTAL costs (cost)
FROM (SELECT BOX
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
January 1, 2012 to 07/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
14/01/2012, 1 August 2012'
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
January 15, 2012 to 21/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
January 22, 2012 to 28/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
29 January 2012 to 31/01/2012 '
END
week, supplier, customer, cost
REPORT)
GROUP BY week, supplier, customer
UNION ALL
SELECT tw.week, vendor, customer or 0
(SELECT week, supplier, customer, TOTAL costs (cost)
FROM (SELECT BOX
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
January 1, 2012 to 07/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
14/01/2012, 1 August 2012'
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
January 15, 2012 to 21/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
January 22, 2012 to 28/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
29 January 2012 to 31/01/2012 '
END
week, supplier, customer, cost
REPORT)
GROUP BY week, supplier, customer), temp_week tw)
GROUP BY week, supplier, customer
ORDER BY supplier, customer, week;
with above query I get below output:
with output voltage)
Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 500 as cost of double union all
Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 200 as cost of double union all
Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 330 as costs of double union all
Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 370 as cost of double union all
Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 300 as cost of double union all
Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 0 as the cost of dual union all
Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, double cost of 0)
Clearly, I used cross join. But I want to get the same result with another way. I don't want to use cross join and Union
Please help me in this.What you desire can be accomplished using the outer join partitioned.
The documentation shows an example of [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2177515] this way to fill the gaps in the data.Here's how you can use it in your case:
SQL> with report as ( 2 select 'vendor_1' as vendor,to_date('1/1/2012','DD/MM/YYYY') supply_date, 'customer_1'as customer,'item_1' as item1, 110 as cost from dual union all 3 select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,120 as c ost from dual union all 4 select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item1,130 as cost from dual union all 5 select 'vendor_1' as vendor,to_date('1/4/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,140 as c ost from dual union all 6 select 'vendor_1' as vendor,to_date('1/10/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item ,200as cost from dual union all 7 select 'vendor_1' as vendor,to_date('1/23/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item,0 as co st from dual union all 8 select 'vendor_1' as vendor,to_date('1/6/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,160 as c ost from dual union all 9 select 'vendor_1' as vendor,to_date('1/7/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,170 as c ost from dual union all 10 select 'vendor_1' as vendor,to_date('1/8/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,180 as c ost from dual union all 11 select 'vendor_1' as vendor,to_date('1/9/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,190 as co st from dual union all 12 select 'vendor_1' as vendor,to_date('1/20/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,300 as c ost from dual 13 ), weeks as ( 14 select to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 week_start 15 , to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 + 6 week_end 16 , level week_pseudo_id 17 from dual 18 connect by level <= 5 /* substitute desired number of weeks */ 19 ) 20 -- 21 -- end-of-test-data 22 -- 23 select to_char(max(weeks.week_start),'DD/MM/YYYY') 24 || ' to ' || 25 to_char(max(weeks.week_end),'DD/MM/YYYY') week 26 , vendor 27 , customer 28 , nvl(sum(cost),0) cost 29 from report 30 partition by (vendor, customer) 31 right outer join weeks 32 on weeks.week_start <= report.supply_date 33 and weeks.week_end >= report.supply_date 34 group by 35 vendor 36 , customer 37 , week_pseudo_id 38 order by 39 vendor 40 , customer 41 , week_pseudo_id 42 / WEEK VENDOR CUSTOMER COST ------------------------ -------- ---------- ---------- 01/01/2012 to 07/01/2012 vendor_1 customer_1 500 08/01/2012 to 14/01/2012 vendor_1 customer_1 200 15/01/2012 to 21/01/2012 vendor_1 customer_1 0 22/01/2012 to 28/01/2012 vendor_1 customer_1 0 29/01/2012 to 04/02/2012 vendor_1 customer_1 0 01/01/2012 to 07/01/2012 vendor_1 customer_2 330 08/01/2012 to 14/01/2012 vendor_1 customer_2 370 15/01/2012 to 21/01/2012 vendor_1 customer_2 300 22/01/2012 to 28/01/2012 vendor_1 customer_2 0 29/01/2012 to 04/02/2012 vendor_1 customer_2 0 10 rows selected.
I have redesigned weeks of date columns for the join which will probably perform better and can possibly use indexes.
I assume that you have no time portion in your supply_date data? If you do, then week_end will need to be modified. -
Need help with the recursive query
I have test table
Create table test (key primary number col_pk,)
number of fins,
number of fo_fv
number of jup_fv
action varchar2 (10)
);
Insert into test values(1,1,1,1,'LOAD');
Insert into test values(2,2,null,2,'ROLL');
Insert into test values(3,3,null,3,'ROLL');
Insert into test values(4,4,null,4,'ROLL');
Insert into test values(5,5,null,5,'ROLL');
Insert into test values (6, null, null, 5.1, 'FLATTEN');
Insert into test values (7, null, null, 5.2, 'FLATTEN');
Insert into test values(8,null,null,1,'SIGNOFF');
Insert into test values (9, null, null, 1,001, 'SIGNOFF');
Insert into test values(10,6,2,6,'LOAD');
Insert into test values (11, null, null, 6.1, 'FLATTEN');
Insert into test values(12,7,1,7,'RELOAD');
Insert into test values(13,null,null,1,'SIGNOFF');
Select * from test;
I want the result of the query in the form below:
COL_PK FINS FO_FV JUP_FV ACTION
---------- ---------- ---------- ---------- ----------
1 1 1 1 LOAD
--------------------------------------------------
2 2 1 2 ROLL
--------------------------------------------------
3 3 1 3 ROLL
--------------------------------------------------
4 4 1 4 ROLL
--------------------------------------------------
ROLL 5 5 1 5
--------------------------------------------------
5.1 6 5 1 FLATTEN
--------------------------------------------------
7 5 1 5.2 FLATTEN
--------------------------------------------------
8 5 1 1 APPROVAL
--------------------------------------------------
9 5 1 APPROVAL 1,001
--------------------------------------------------
10 6 2 6 LOAD
--------------------------------------------------
11 6 2 6.1 FLATTEN
--------------------------------------------------
12 7 1 7 RELOAD
--------------------------------------------------
13 7 1 1 APPROVAL
--------------------------------------------------
Help, please
Hello
This sounds like a job for the analytical LAST_VALUE function:
SELECT col_pk
LAST_VALUE (fins IGNORE NULLS)
COURSES (ORDER BY col_pk) AS fins2
LAST_VALUE (fo_fv IGNORE NULLS)
COURSES (ORDER BY col_pk) AS fo_fv2
jup_fv
action
OF the test
ORDER BY col_pk
;
Output:
COL_PK FINS2 FO_FV2 JUP_FV ACTION
---------- ---------- ---------- ---------- ----------
1 1 1 1 LOAD
2 2 1 2 ROLL
3 3 1 3 ROLL
4 4 1 4 ROLL
ROLL 5 5 1 5
5.1 6 5 1 FLATTEN
7 5 1 5.2 FLATTEN
8 5 1 1 APPROVAL
9 5 1 APPROVAL 1,001
10 6 2 6 LOAD
11 6 2 6.1 FLATTEN
12 7 1 7 RELOAD
13 7 1 1 APPROVAL
-
I need help in the sql statement
Hi all
im working in the hr schema
I need sql statement to answer my question
I need information to all employees
where average wage = average wage department 50
Sorry I can't speak English very well
I thank allThere is no need to do so in the two motions. All you need is:
select * from ( select e.*, avg(case department_id when 50 then salary end) over() dept_50_avg_sal from hr.employees e ) where salary <= dept_50_avg_sal / EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 198 Donald OConnell DOCONNEL 650.507.9833 21-JUN-07 SH_CLERK 2600 124 50 3475.55556 199 Douglas Grant DGRANT 650.507.9844 13-JAN-08 SH_CLERK 2600 124 50 3475.55556 115 Alexander Khoo AKHOO 515.127.4562 18-MAY-03 PU_CLERK 3100 114 30 3475.55556 116 Shelli Baida SBAIDA 515.127.4563 24-DEC-05 PU_CLERK 2900 114 30 3475.55556 117 Sigal Tobias STOBIAS 515.127.4564 24-JUL-05 PU_CLERK 2800 114 30 3475.55556 118 Guy Himuro GHIMURO 515.127.4565 15-NOV-06 PU_CLERK 2600 114 30 3475.55556 119 Karen Colmenares KCOLMENA 515.127.4566 10-AUG-07 PU_CLERK 2500 114 30 3475.55556 125 Julia Nayer JNAYER 650.124.1214 16-JUL-05 ST_CLERK 3200 120 50 3475.55556 126 Irene Mikkilineni IMIKKILI 650.124.1224 28-SEP-06 ST_CLERK 2700 120 50 3475.55556 127 James Landry JLANDRY 650.124.1334 14-JAN-07 ST_CLERK 2400 120 50 3475.55556 128 Steven Markle SMARKLE 650.124.1434 08-MAR-08 ST_CLERK 2200 120 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 129 Laura Bissot LBISSOT 650.124.5234 20-AUG-05 ST_CLERK 3300 121 50 3475.55556 130 Mozhe Atkinson MATKINSO 650.124.6234 30-OCT-05 ST_CLERK 2800 121 50 3475.55556 131 James Marlow JAMRLOW 650.124.7234 16-FEB-05 ST_CLERK 2500 121 50 3475.55556 132 TJ Olson TJOLSON 650.124.8234 10-APR-07 ST_CLERK 2100 121 50 3475.55556 133 Jason Mallin JMALLIN 650.127.1934 14-JUN-04 ST_CLERK 3300 122 50 3475.55556 134 Michael Rogers MROGERS 650.127.1834 26-AUG-06 ST_CLERK 2900 122 50 3475.55556 135 Ki Gee KGEE 650.127.1734 12-DEC-07 ST_CLERK 2400 122 50 3475.55556 136 Hazel Philtanker HPHILTAN 650.127.1634 06-FEB-08 ST_CLERK 2200 122 50 3475.55556 138 Stephen Stiles SSTILES 650.121.2034 26-OCT-05 ST_CLERK 3200 123 50 3475.55556 139 John Seo JSEO 650.121.2019 12-FEB-06 ST_CLERK 2700 123 50 3475.55556 140 Joshua Patel JPATEL 650.121.1834 06-APR-06 ST_CLERK 2500 123 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 142 Curtis Davies CDAVIES 650.121.2994 29-JAN-05 ST_CLERK 3100 124 50 3475.55556 143 Randall Matos RMATOS 650.121.2874 15-MAR-06 ST_CLERK 2600 124 50 3475.55556 144 Peter Vargas PVARGAS 650.121.2004 09-JUL-06 ST_CLERK 2500 124 50 3475.55556 180 Winston Taylor WTAYLOR 650.507.9876 24-JAN-06 SH_CLERK 3200 120 50 3475.55556 181 Jean Fleaur JFLEAUR 650.507.9877 23-FEB-06 SH_CLERK 3100 120 50 3475.55556 182 Martha Sullivan MSULLIVA 650.507.9878 21-JUN-07 SH_CLERK 2500 120 50 3475.55556 183 Girard Geoni GGEONI 650.507.9879 03-FEB-08 SH_CLERK 2800 120 50 3475.55556 186 Julia Dellinger JDELLING 650.509.3876 24-JUN-06 SH_CLERK 3400 121 50 3475.55556 187 Anthony Cabrio ACABRIO 650.509.4876 07-FEB-07 SH_CLERK 3000 121 50 3475.55556 190 Timothy Gates TGATES 650.505.3876 11-JUL-06 SH_CLERK 2900 122 50 3475.55556 191 Randall Perkins RPERKINS 650.505.4876 19-DEC-07 SH_CLERK 2500 122 50 3475.55556 EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL ----------- -------------------- ------------------------- ------------------------- -------------------- --------- ---------- ---------- -------------- ---------- ------------- --------------- 194 Samuel McCain SMCCAIN 650.501.3876 01-JUL-06 SH_CLERK 3200 123 50 3475.55556 195 Vance Jones VJONES 650.501.4876 17-MAR-07 SH_CLERK 2800 123 50 3475.55556 196 Alana Walsh AWALSH 650.507.9811 24-APR-06 SH_CLERK 3100 124 50 3475.55556 197 Kevin Feeney KFEENEY 650.507.9822 23-MAY-06 SH_CLERK 3000 124 50 3475.55556 37 rows selected. SQL>
SY.
-
Need help on a SQL query.
Greetings,
Here are two columns in a table.
col1 col2
1 a
1 b
1 c
2 e
2 a
2 f
3 g
3B
3 a
The query must be such that it should display the output in the following format:
col1 col2
1 a, b, c
2, e, e, f
3 g, b, a
Thank you
NSYou can use WM_CONCAT. Ex:
SELECT col1, WM_CONCAT(col2) FROM your_table GROUP BY col1
-
I have a table 'departments' with the following fields:
dep_id, parent_dep_id.
1 5
2
3 4
4
5 2
How can I write SQL to return the department (division) parent of higher level for each Department:
dep_id, div_id
1 2
2 2
3 4
4 4
5 2
Thank you.SQL> create table t (dep_id,parent_dep_id) 2 as 3 select 1, 5 from dual union all 4 select 2, null from dual union all 5 select 3, 4 from dual union all 6 select 4, null from dual union all 7 select 5, 2 from dual 8 / Tabel is aangemaakt. SQL> select dep_id 2 , max(connect_by_root dep_id) keep (dense_rank last order by level) div_id 3 from t 4 connect by prior dep_id = parent_dep_id 5 group by dep_id 6 / DEP_ID DIV_ID ---------- ---------- 1 2 2 2 3 4 4 4 5 2 5 rijen zijn geselecteerd.
Kind regards
Rob. -
Hi all
I have a requirement to get all the items contained in the link of the item for the two States of 2 payroll.
I also want to recover what elements exist only in unique payroll.
Case 1: Item exists in both States to pay.
Case 2: Item exists in only one of the payroll.
Item: XX_ELEMENT
Element_id = 140
Payroll_id 1 = 40
payroll_id 2 = 50
Example table:
element_id Payroll_id
140 40
140 50
140 60
141 40
Desired output:
Element on the payroll
140 40,50 (or ' the two States of payroll)
141 40
Here is the code I am trying.
SELECT DISTINCT
LINK. PAYROLL_ID,
PAF. PAYROLL_NAME,
ELEMENT_LINK_ID,
PF. ELEMENT_TYPE_ID,
LINK. LINK_TO_ALL_PAYROLLS_FLAG,--IN('Y','N')
PTL. ELEMENT_NAME ARABIC,
PF. ELEMENT_NAME ENGLISH
LINK PAY_ELEMENT_LINKS_F,
PAY_ELEMENT_TYPES_F_TL PTL,
PAY_ELEMENT_TYPES_F PF,
PAF PAY_ALL_PAYROLLS_F
WHERE PF. ELEMENT_TYPE_ID = 140 AND
PAF. PAYROLL_ID (+) IS LINK. PAYROLL_ID
AND PF. ELEMENT_TYPE_ID = PTL. ELEMENT_TYPE_ID
AND PF. ELEMENT_TYPE_ID (+) IS LINK. ELEMENT_TYPE_ID
AND THE PTL. LANGUAGE = "AR".
AND TRUNC (SYSDATE) BETWEEN PF. EFFECTIVE_START_DATE AND PF. EFFECTIVE_END_DATE
AND (TRUNC (SYSDATE) BETWEEN PAF. EFFECTIVE_START_DATE AND OF THE PAF. EFFECTIVE_END_DATE OR LINK. PAYROLL_ID IS NULL)
AND TRUNC (SYSDATE) BETWEEN LINK. EFFECTIVE_START_DATE AND LINK. EFFECTIVE_END_DATE
AND THE LINK. PAYROLL_ID IN (40,50)
Kind regards
Afzal.
Once you have your set of element_id and payroll_id you can use count (distinct) to get the number of different values of payroll_id by element_id. Something like
Select element_id, count (distinct payroll_id) cnt, max (payroll_id) max_pr the subquery by element_id group
You can then use a decoding against the column of the cnt to display 'two' or max_pr.
You haven't posted your version of Oracle, but if you are on at least 11.2.0.1 then you can also use listagg on the separate set of element_id and payroll_id
-
Help with making SQL query references to column aliases in the Case statement
I need help with a sql query that I'm trying. I can go about it the wrong way, but I would be grateful if I could get any suggestions on possible solutions. This is my query:
SELECT DISTINCT spriden_pidm, spriden_id id, spriden_last_name | ',' | spriden_first_name name,
CASE
WHEN rcresar_comm_code_01 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_01
WHEN rcresar_comm_code_02 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_02
WHEN rcresar_comm_code_03 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_03
WHEN rcresar_comm_code_04 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_04
WHEN rcresar_comm_code_05 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_05
WHEN rcresar_comm_code_06 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_06
WHEN rcresar_comm_code_07 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_07
WHEN rcresar_comm_code_08 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_08
WHEN rcresar_comm_code_09 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_09
WHEN rcresar_comm_code_10 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_10
END acg_elig_comm_code
CASE
WHEN acg_elig_comm_code = ' 268' THEN 'rigorous HS course. "
WHEN acg_elig_comm_code = '269' THEN ' 2 or several AP or IB"
WHEN acg_elig_comm_code = '270' THEN 'NOC as possible ".
END comm_code_description
OF spriden, rcresar, rcrapp1
WHERE (rcresar_comm_code_01 IN ('268 ', '269', ' 270')
OR rcresar_comm_code_02 ('268 ', '269', ' 270')
OR rcresar_comm_code_03 ('268 ', '269', ' 270')
OR rcresar_comm_code_04 ('268 ', '269', ' 270')
OR rcresar_comm_code_05 ('268 ', '269', ' 270')
OR rcresar_comm_code_06 ('268 ', '269', ' 270')
OR rcresar_comm_code_07 ('268 ', '269', ' 270')
OR rcresar_comm_code_08 ('268 ', '269', ' 270')
OR rcresar_comm_code_09 ('268 ', '269', ' 270')
OR rcresar_comm_code_10 ('268 ', '269', ' 270'))
Rcresar_aidy_code = & aidy_code
AND rcrapp1_aidy_code = rcresar_aidy_code
AND rcrapp1_curr_rec_ind = 'Y '.
AND rcrapp1_seq_no = rcresar_seq_no
AND spriden_pidm = rcresar_pidm
AND rcrapp1_pidm = rcresar_pidm
AND spriden_change_ind IS NULL
ORDER BY name
The second case statement is where I don't know exactly what it takes to get what I want.
Output should be like:
spriden_pidm name ID acg_elig_comm_code comm_code_description
«0000000000', ' 1111111111 ","John Doe","268", «rigorous HS race"»
If I take the second case statement it works great except that I do not have my comm_code description column. My question is how can I use my first statement value box to determine this column? I think that I need a case statement as I have, but I don't know how to reference the value of acg_elig_comm_code. Any help would be greatly appreciated. Thank you.
Published by: blackhole82 on January 20, 2009 09:20Hello
You cannot use the alias column in the query, even where it is set (except in the ORDER BY clause).
You can set the alias in a subquery and then use it in a great query, like this:WITH sub_q AS ( SELECT DISTINCT spriden_pidm,spriden_id id, spriden_last_name||', '||spriden_first_name name, CASE WHEN rcresar_comm_code_01 IN ('268','269','270') THEN rcresar_comm_code_01 WHEN rcresar_comm_code_02 IN ('268','269','270') THEN rcresar_comm_code_02 WHEN rcresar_comm_code_03 IN ('268','269','270') THEN rcresar_comm_code_03 WHEN rcresar_comm_code_04 IN ('268','269','270') THEN rcresar_comm_code_04 WHEN rcresar_comm_code_05 IN ('268','269','270') THEN rcresar_comm_code_05 WHEN rcresar_comm_code_06 IN ('268','269','270') THEN rcresar_comm_code_06 WHEN rcresar_comm_code_07 IN ('268','269','270') THEN rcresar_comm_code_07 WHEN rcresar_comm_code_08 IN ('268','269','270') THEN rcresar_comm_code_08 WHEN rcresar_comm_code_09 IN ('268','269','270') THEN rcresar_comm_code_09 WHEN rcresar_comm_code_10 IN ('268','269','270') THEN rcresar_comm_code_10 END acg_elig_comm_code -- Originally posted with , here (error) FROM spriden, rcresar, rcrapp1 WHERE (rcresar_comm_code_01 IN ('268','269','270') OR rcresar_comm_code_02 IN ('268','269','270') OR rcresar_comm_code_03 IN ('268','269','270') OR rcresar_comm_code_04 IN ('268','269','270') OR rcresar_comm_code_05 IN ('268','269','270') OR rcresar_comm_code_06 IN ('268','269','270') OR rcresar_comm_code_07 IN ('268','269','270') OR rcresar_comm_code_08 IN ('268','269','270') OR rcresar_comm_code_09 IN ('268','269','270') OR rcresar_comm_code_10 IN ('268','269','270')) AND rcresar_aidy_code = &aidy_code AND rcrapp1_aidy_code = rcresar_aidy_code AND rcrapp1_curr_rec_ind = 'Y' AND rcrapp1_seq_no = rcresar_seq_no AND spriden_pidm = rcresar_pidm AND rcrapp1_pidm = rcresar_pidm AND spriden_change_ind IS NULL ) SELECT sub_q.*, CASE WHEN acg_elig_comm_code = '268' THEN 'Rigorous HS course' WHEN acg_elig_comm_code = '269' THEN '2 or more AP or IB' WHEN acg_elig_comm_code = '270' THEN 'ACG possible' END comm_code_description FROM sub_q ORDER BY name
Furthermore, you might think to rearrange your table, so that you do not have 10 columns (rcresar_comm_code_01, rcresar_comm_code_02,...) that essentially do the same thing. The usual way to handle this kind of one-to-many relationship is to have all rcresar_comm_codes in a separate table, one per line, with a pointer to the table where you have them now.
Published by: Frank Kulash, January 20, 2009 11:35
Syntax error has been corrected -
Help me with SQL Query to retrieve data from a view
Hello Guru,
I need help in my sql query.
I use SQL TeraData.
I want an Oracle result in the following form-
Open tickets
Open months failure / Repair Service s/o improvement request Total general
2009-01-2 4 4 5 15
2009-02 1 0 2 3 6
2009-03 4 1 2 2 9
Grand Total 7 5 8 10 30
I wrote the query as where - TIME_PERIOD, RQST_TYPE_DM and DEMAND_SUMMARY_FCT are the points of view and I extract the data from the views only.
Select NVL (CA. TIME_PERIOD. PERIOD_CD, 'Total') THAT year.
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% of Break' THEN 1 END) as BreakFix
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'N/a', 1 END) by n/a
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'Improvement' THEN 1 END) accessories
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% Service' THEN 1 END) as ServiceRequests
COUNT (CA. RQST_TYPE_DM. RQSTTYP_DESC) AS grand_total
FROM CA. TIME_PERIOD, CA. RQST_TYPE_DM, CA. DEMAND_SUMMARY_FCT
WHERE (CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = CA. RQST_TYPE_DM. RQSTTYP_ID)
AND (CASE
WHEN CA. DEMAND_SUMMARY_FCT. MONTH_ID = CA. TIME_PERIOD. PERIOD_ID, 1
WHEN {fn concat ({fn concat (SUBSTR (CA. TIME_PERIOD. {(PERIOD_CD, 3, 4),'-')}, SUBSTR (CA. TIME_PERIOD. PERIOD_CD, 7, 2))} BETWEEN ' 2009-01' AND ' 2009-03' THEN 1
WHEN CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = '1' then 1
END) = 1
GROUP BY ROLLUP (CA. TIME_PERIOD. PERIOD_CD)
After executing the query, I get the following error:
3076: syntax Error: Data Type 'Time' does not match a defined Type name.
:( Kindly help me with this and let me know where I'm wrong... Please.Messages indicates something wrong with your data... It would seem that the data does not match your format mask.
Thus, the data or the format mask.
-
Help with time operations invloving the SQL query
I created 2 tables in my SQL. One is the user_info_table table that stores the connection time and time zone of login for each user. The other is the post_table that stores user postid, who makes the post time post and time zone for each message.
CREATE TABLE user_info ( user_id VARCHAR(20), login_date DATE, login_time_zone VARCHAR(20), PRIMARY KEY (user_id) );
Some examples of data for my paintings is as below.CREATE TABLE post_table ( post_id VARCHAR(20), user_id VARCHAR(20), datepost DATE, time_zone VARCHAR(20), PRIMARY KEY (post_id), FOREIGN KEY (user_id) REFERENCES user_info(user_id) ON DELETE CASCADE ) ;
I need to write a SQL query which - is the user whose time difference between the time of the connection and the last time when he or she wrote a post is the smallest. I need to consider the time zones here as well.INSERT INTO user_info VALUES( 'u1', to_date('9/17/2009 20:00','MM/DD/YYYY mi:ss'), -2 ); INSERT INTO user_info VALUES( 'u2', to_date('9/17/2009 19:55','MM/DD/YYYY mi:ss'), -4 ); INSERT INTO post_table VALUES( 'p1', 'u1', to_date('9/17/2009 20:50','MM/DD/YYYY mi:ss'), 6 ); INSERT INTO post_table VALUES( 'p2', 'u2', to_date('9/17/2009 20:30','MM/DD/YYYY mi:ss'), -5 ); INSERT INTO post_table VALUES( 'p3', 'u2', to_date('9/18/2009 6:00','MM/DD/YYYY mi:ss'), 2 ); INSERT INTO post_table VALUES( 'p4', 'u1', to_date('9/17/2009 21:00','MM/DD/YYYY mi:ss'), -3 );
I am not sure if time_zone must be of type VARCHAR or TIMESTAMP then have created as a VARCHAR in my paintings.
Someone help me please to form this query.
PS: How can I tags < code > user in this forum to write sql statements.
Published by: user11994430 on October 9, 2009 17:59You can do this by adding a clause of "HAVING" as shown below. However, with your test defined data it returns ZERO rows because for all users of the MAX (DATEPOST) IS LESS than MAX (LOGIN_DATE)
SELECT USER_ID FROM ( SELECT USER_ID , DENSE_RANK() OVER (ORDER BY POST_LOGIN_DIFF) RNK FROM ( SELECT USER_INFO.USER_ID , MAX(DATEPOST) - MAX(LOGIN_DATE) AS POST_LOGIN_DIFF FROM USER_INFO JOIN POST_TABLE ON POST_TABLE.USER_ID = USER_INFO.USER_ID GROUP BY USER_INFO.USER_ID HAVING MAX(DATEPOST) > MAX(LOGIN_DATE) ) ) WHERE RNK = 1
-
Need help on the re-write of a query
Hello
Recently, I've migrated database from MSSQL to Oracle using SQL Developer tool.
There is a table, "PERSONALIZATIONITEMS" that has a column of data type XML, ('ACTIONS' and 'ELIGIBILITYDEFINITION') in MSSQL, was translated into Oracle CLOB data type;
PersonalizationItems table in MSSQL
[PersonalizationItemID] [int] IDENTITY (1,1)
[PersonalizationID] [smallint]
[PersonalizationContentTypeID] [smallint]
[ContentDescription] [nvarchar] (50)
[EligibilityDefinition] [xml]
[Actions] [xml]
[Priority] [decimal] (5, 2)
[IsActive] [ILO]
[DateCreated] [smalldatetime]
[DateModified] [datetime]
Table PersonalizationItems in Oracle
PERSONALIZATIONITEMID NOT NULL NUMBER (10)
PERSONALIZATIONID NOT NULL NUMBER (5)
PERSONALIZATIONCONTENTTYPEID NUMBER (5)
CONTENTDESCRIPTION NVARCHAR2 (50)
ELIGIBILITYDEFINITION NOT NULL CLOB
ACTIONS NOT NULL CLOB
PRIORITY NOT NULL NUMBER (5.2)
ISACTIVE NOT NULL NUMBER (1)
DATECREATED NOT NULL DATE
DATEMODIFIED NOT NULL DATE
I'd like to get your opinion/advice here on how I would write the sql query in Oracle which would be equivalent to the following query in MSSQL.
SELECT PersonalizationItemID PersonalizationID , Actions.value ('(/ Actions/Action/ContextItems/ContextItem [@Key = "FlowcationID"] /@Value) [1] ',' nvarchar (250)') AS FlowcationID FROM dbo. PersonalizationItems
(OÙ_Actions.exist('(/Actions/Action/@ActionData)[contains(.,"~/SharedUI/UserControls/Commerce/UpsellDisplayAdapter.ascx")]') = 1
AND IsActive = 1 Thank you.
I finally managed to re - write the query in Oracle that provide the same output as the query in MSSQL.
SELECT
PersonalizationItemID,
PersonalizationID,
extractValue(actions,'/Actions/Action/ContextItems/ContextItem[@Key="FlowcationID"]/@Value') "FlowcationID".
Of
PersonalizationItems
WHERE
existsNode (actions,'/ Actions/Action [@ActionData="~/SharedUI/UserControls/Commerce/UpsellDisplayAdapter.ascx"]') = 1
AND IsActive = 1;
Maybe you are looking for
-
I paid £280 for a good condition 2014 iMac 21.5 "original box & accessories. Logic pro and final cut installed (no interest for me).
-
Canoe use Wi - Fi on my Satellite L750
I have some problems with a Wi - Fi connection :( I have the Toshiba Satellite L750. I had installed the new Windows 7. Everything is working exepct Wi - Fi. I had downloaded the drivers of the al. I am turing on Wi - Fi and... nothing.Is to show tha
-
Windows xp. I get this message when I try to share the media in windows media player 11 "sharing multimedia files has been disabled because a Windows setting or a required component has changed. For additional assistance, click Web Help. "I can't tur
-
So, recently, I installed a new router. After restarting my modem as indicated in after connecting the router to the modem, I was surprised to see that the wireless network has been renamed to (name) 2. I continued with the installation and soon foun
-
limit bandwidth telepresence Tandberg ex90
Hello I have 5 ex90s. Location1 (L1): 2 Location2 (L2): 1 Location3 (L3): 1 Location4 (L4): 1 When ex90 in place call each other, then they can use all the bandwidth as they wish. When a place ex90 calls ex90 in another place, they can use only 1.5 M