Joining query with single row result
dear all,
i have two tables
create table item(item_id number primary key,
item_desc varchar2(200));
create table item_properties(item_id number references item(item_id),
property_name varchar2(20),
property_value varchar2(100));i insert the following records
insert into items values(1,'CPU');
insert into item_properties values(1,'RAM','2gb');
insert into item_properties values(1,'PROCESSOR','2ghz');
insert into item_properties values(1,'HARDDISK','2ghz');
commit;now i want a query which produce the following results
item_id RAM PROCESSOR HARDDISK
1 2gb 2ghz 2TBHow to generate this result?
i have create a query but it generate multiple rows, instead i need in a single row like above.
select i.item_id,p.property_value from items i , item_properties p
where i.item_id=p.item_id and i.item_id=1;Kind thanks.
Edited by: Maahjoor on May 7, 2013 12:22 AM
select i.item_id,
max(decode(p.property_name,'RAM',p.property_value)) ram,
max(decode(p.property_name,'PROCESSOR',p.property_value)) processor,
max(decode(p.property_name,'HARDDISK',p.property_value)) hd
from items i , item_properties p
where i.item_id=p.item_id
and i.item_id=1
group by i.item_id;Or pivot in 11g
with details as
select i.item_id,p.property_name,p.property_value
from item i , item_properties p
where i.item_id=p.item_id
and i.item_id=1
select *
from details
pivot
max(property_value) for property_name in ('RAM','PROCESSOR','HARDISK')
);Edited by: jeneesh on May 7, 2013 1:04 PM
Similar Messages
-
Several reports on joined master-detail tables with single row source
I have 1 master table (Fixed Assets) and several datail tables (Improvements, Depreciation, ...)
I need to create several reports based on them all with criteria
'Select ALL from Master and join details
/1 total row from details for 1 master row/
filtered by [on_date <= report_date]'
How to do it better and not copy same code in every report?
As mentioned on this forum, ApEx is not able to use RefCursor as row source for ApEx reports
So I tried this Tom Kyte's example:
create type apex_user.myRecordType as object
(seq int,
a int,
b varchar2(10),
c date
Create Or Replace Type Apex_User.Mytabletype As Table Of Apex_User.Myrecordtype;
create or replace function Apex_User.my_function return Apex_User.myTableType
Is
l_data Apex_User.myTableType;
Begin
l_data := Apex_User.myTableType();
for i in 1..5
loop
L_Data.Extend;
l_data(i) :=Apex_User.myRecordType(i, i, 'row ' || i, sysdate+i);
end loop;
Return L_Data;
End;
Select *
from TABLE (cast(Apex_User.my_function() as Apex_User.mytableType))
Where C > Sysdate+1
Order By Seq Desc
SEQ A B C
5 5 row 5 22.08.2010
4 4 row 4 21.08.2010
3 3 row 3 20.08.2010
2 2 row 2 19.08.2010
4 Rows Selected
- and it really works from ApEx reports.
The questions are:
1) is this the best solution for my task (one centralized code for several reports with parameter filtering detail tables)?
2) how to change example properly to have here -
loop
L_Data.Extend;
l_data(i) :=Apex_User.myRecordType(i, i, 'row ' || i, sysdate+i);
end loop;
- simple SELECT from my MASTER-DETAILS joined tables?Hi,
if (row != null)
Row masterRow = row;
vo.setCurrentRow(masterRow);
// not needed : getMesReponsesPourTiersVO1().executeQuery();
You shouldnot execute the child VO after setting current row in master VO.
When the current row is set in master VO, then the child rows will get refreshed automatically.
Cheers,
Prasanna -
Left join query with join of three tables
I'm trying to build a query which has me stumped. Most of the query is fairly straightforward but I've run into an issue I'm not sure how to solve.
Background:
We have actions stored in i_action.
We have the available attributes for each type of action. The available attributes for each action are described in shared_action_attribute. Each type of action may have up to three attributes or none at all.
We have the values stored for the attributes in i_attribute_value.
A written example:
We have a transfer action (action_code B4). The entry of the B4 action into i_action records the fact that the transfer occurred and the date on which it occurred. The available attributes for a transfer action are the receiving function code, the receiving unit number, and the transfer reason code. These available attribute types and their order are stored in shared_action_attribute. The actual values of the attributes for a specific transfer action are stored in i_attribute_value.
Now i_action and i_attribute_value can be directly linked through action_seq in i_action and ia_action_seq in i_attribute_value. A left join built between these two tables provides results for all actions (including actions which have no attributes) and attribute values (see query 1 below).
There are two issues. First, I only want the first two attributes. In order to specify the first two attributes, I also have to link i_attribute_value to shared_action_attribute (which is where the order is stored). I can build a simple query (without the left join) linking the three tables but then actions with no attributes would be excluded from my result set (see query 2 below).
The second issue is that I would actually like one row returned for each action with first_attribute and second_attribute as columns instead of two rows.
The final query will be used to create a materialized view.
Here are the tables and examples of what's stored in them:
TABLE i_action
Name Type
ACTION_SEQ NUMBER(10)
ACTION_DATE DATE
ACTION_CODE VARCHAR2(3)
DELETED VARCHAR2(1)
EXAMPLE ROWS
ACTION_SEQ ACTION_DATE ACTION_CODE DELETED
45765668 09-OCT-09 B2 A
45765670 09-OCT-09 BA A
45765672 09-OCT-09 B6 A
45765673 09-OCT-09 B4 A
45765674 09-OCT-09 G1 A
45765675 09-OCT-09 M3 A
TABLE i_attribute_value
Name Type
IA_ACTION_SEQ NUMBER(10)
SACTATT_SACT_CODE VARCHAR2(3)
SACTATT_SAT_TYPE VARCHAR2(3)
VALUE VARCHAR2(50)
EXAMPLE ROWS
IA_ACTION_SEQ SACTATT_SACT_CODE SACTATT_SAT_TYPE VALUE
45765668 B2 ACO 37B
45765670 BA ROA D
45765670 BA ROR P
45765672 B6 CAT C
45765673 B4 RFC E
45765673 B4 TRC P
45765673 B4 RUN 7
45765674 G1 SS 23567
45765674 G1 ASG W
TABLE shared_action_attribute
Name Type
SACT_CODE VARCHAR2(3)
SAT_TYPE VARCHAR2(3)
ORDER NUMBER(2)
TITLE VARCHAR2(60)
EXAMPLE ROWS
SACT_CODE SAT_TYPE ORDER TITLE
B2 ACO 1 Office code
BA ROR 1 Reason for reopen
BA ROA 2 Reopen authority
B6 CAT 1 Category
B4 RFC 1 Receiving function code
B4 RUN 2 Receiving unit code
B4 TRC 3 Transfer reason code
G1 SS 1 Staff sequence
G1 ASG 2 Assignment reason
QUERY 1:
This is my current query along with its results. Most of it is straightforward select but one column is populated using the last_value analytical function (thanks to you guys). The last column in the below view stores the attribute value. What I want is to replace that single column with two columns named first_attribute and second_attribute and to eliminate any other attributes.
SELECT ia.action_seq, ia.action_date, ia.action_code cod,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = 'G1'
AND iav.sactatt_sat_type = 'SS'
THEN VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
ia.serial_number, ia.action_seq),
'67089'
) staff_seq,
value
FROM i_action ia LEFT JOIN i_attribute_value iav
ON iav.ia_action_seq = ia.action_seq
WHERE ia.deleted = 'A';
ACTION_SEQ ACTION_DA COD STAFF_SEQ VALUE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 D
45765670 09-OCT-09 BA 67089 P
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E
45765673 09-OCT-09 B4 67089 P
45765673 09-OCT-09 B4 67089 7
45765674 09-OCT-09 G1 23567 23567
45765674 09-OCT-09 G1 23567 W
45765675 09-OCT-09 M3 23567
QUERY 2:
This query limits to the first two attributes but it also drops actions which have no attributes and it still creates multiple rows for each action instead of a single row with two columns for the attributes.
SELECT ia.action_seq, ia.action_date, ia.action_code cod,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = 'G1'
AND iav.sactatt_sat_type = 'SS'
THEN VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
ia.serial_number, ia.action_seq),
'67089'
) staff_seq,
value
FROM shared_action_attribute saa, ims_action ia, ims_attribute_value iav
WHERE iav.ia_action_seq = ia.action_seq
AND iav.sactatt_sact_code = saa.sact_code
AND iav.sactatt_sat_type = saa.sat_type
AND saa.display_order IN ('1','2')
AND ia.deleted = 'A';
ACTION_SEQ ACTION_DA COD VALUE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 D
45765670 09-OCT-09 BA 67089 P
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E
45765673 09-OCT-09 B4 67089 7
45765674 09-OCT-09 G1 23567 23567
45765674 09-OCT-09 G1 23567 W
I found this pretty complex to try to write out - I hope I've been clear.
Thanks so much!Ok, here's more information with a simplified question. I figured out the syntax for building my query with the three tables. My final query returns multiple rows (multiple attributes per action). Instead of multiple rows, I'd like two columns (first_attribute, and second_attribute) in a single row (I only need the first two attributes).
Here's the action table:
CREATE TABLE I_ACTION
ACTION_SEQ NUMBER(10) NOT NULL,
ACTION_DATE DATE,
ACTION_CODE VARCHAR2(3 BYTE) NOT NULL,
DELETED VARCHAR2(1 BYTE),
);With the following rows added:
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765668, '09-oct-2009', 'B2', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765670, '09-oct-2009', 'BA', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765672, '09-oct-2009', 'B6', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765673, '09-oct-2009', 'B4', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765674, '09-oct-2009', 'G1', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765675, '09-oct-2009', 'M3', 'A');
COMMIT;The attribute table is:
CREATE TABLE I_ATTRIBUTE_VALUE
IA_ACTION_SEQ NUMBER(10) NOT NULL,
SACTATT_SACT_CODE VARCHAR2(3 BYTE) NOT NULL,
SACTATT_SAT_TYPE VARCHAR2(3 BYTE) NOT NULL,
VALUE VARCHAR2(50 BYTE),
);With the following rows:
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765668, 'B2', 'ACO', '37B');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765670, 'BA', 'ROR', 'P');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765670, 'BA', 'ROA', 'D');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765672, 'B6', 'CAT', 'C');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765673, 'B4', 'RFC', 'E');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765673, 'B4', 'RUN', '7');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765673, 'B4', 'TRC', 'P');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765674, 'G1', 'SS', '23567');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765674, 'G1', 'ASG', 'W');
COMMIT;And finally, the shared table:
CREATE TABLE SHARED_ACTION_ATTRIBUTE
SACT_CODE VARCHAR2(3 BYTE) NOT NULL,
SAT_TYPE VARCHAR2(3 BYTE) NOT NULL,
TITLE VARCHAR2(25 BYTE) NOT NULL,
DISPLAY_ORDER NUMBER(2) NOT NULL
);With the following rows:
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B4', 'RFC', 'Y', 'Rcv. Function Code', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B6', 'CAT', 'Y', 'Category', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('G1', 'SS', 'Y', 'Staff Name', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B2', 'ACO', 'Y', '"Other" Office Code', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B4', 'RUN', 'Y', 'Receiving Unit Number', 2);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B6', 'LEP', 'N', 'LEP Issue/Sub Category', 2);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B4', 'TRC', 'Y', 'Transfer Reason Code', 3);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B6', 'NEP', 'N', 'NEP Issue', 3);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('G1', 'ASG', 'Y', 'Assignment Reason', 2);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B2', 'MSN', 'S', 'Machine Serial Number', 3);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('BA', 'ROR', 'Y', 'Reopen Reason', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('BA', 'ROA', 'Y', 'Reopen Authority', 2);
COMMIT;Now, this is my current query (it's changed from my first post):
SELECT ia.action_seq, ia.ici_charge_inquiry_seq, ia.action_date,
ia.serial_number, ia.reporting_office, ia.reporting_function,
ia.reporting_unit, ia.action_code, ia.machine_serial_number,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = 'G1'
THEN VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
ia.serial_number, ia.action_seq),
'67089'
) staff_seq,
(CASE
WHEN display_order = '1'
THEN VALUE
END) first_attribute,
(CASE
WHEN display_order = '2'
THEN VALUE
END) second_attribute
FROM ims_action ia
LEFT JOIN ims_attribute_value iav
ON iav.ia_action_seq = ia.action_seq
LEFT JOIN shared_action_attribute
ON sactatt_sact_code = sact_code
AND sactatt_sat_type = sat_type
WHERE ia.deleted = 'A';Which gives me the following results:
ACTION_SEQ ACTION_DA ACT STAFF_SEQ FIRST_ATTRIBUTE SECOND_ATTRIBUTE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 D
45765670 09-OCT-09 BA 67089 P
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E
45765673 09-OCT-09 B4 67089 7
45765673 09-OCT-09 B4 67089
45765674 09-OCT-09 G1 23567 W
45765674 09-OCT-09 G1 23567 23567
45765675 09-OCT-09 M3 23567 The result I WANT is similar but I want the two separate attribute columns on one row as such:
ACTION_SEQ ACTION_DA ACT STAFF_SEQ FIRST_ATTRIBUTE SECOND_ATTRIBUTE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 P D
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E 7
45765674 09-OCT-09 G1 23567 23567 W
45765675 09-OCT-09 M3 23567 Thanks so much! -
Still problem with single-row subquery returns more than one row
//i did join each table but query runs forever and fail. looks Cartesian join so comes up the following SQL
the following query has a problem. would you please help me, please
Select pe.expense_id
,PE.CODE
,PE.PROJECT_ID
,PE.LDATE
,PE.INAMOUNT pe_amount
,(SELECT TRX.INV_AMOUNT FROM TRXEXPENSES TRX
WHERE PE.EXPENSE_ID=TRX.EXPENSE_ID) AS invamount
,(SELECT RE.AMOUNT FROM REEXPENSES RE WHERE
PE.EXPENSE_ID=RE.EXPENSE_ID) AS recogamount
,(SELECT MLE.M_AMOUNT FROM MATEXPENSES MLE
WHERE PE.EXPENSE_ID=MLE.EXPENSE_ID) AS matamount
from EXPENSES PE
where pe.expense_id=5600
group by expense_id,CODE,PROJECT_ID,LDATE,inamount
//get error message
ora-01427:single-row subquery returns more than one row
//check database
select expense_id,count(*) from TRXEXPENSES
where expense_id in(select expense_id from
expenses)
group by expense_id
having count(*)>1
//here is duplicate record a lot
EXPENSE_ID COUNT(*)
4176 2
5600 3
9572 2
9573 2
9574 2Yes, Expense_id has so many returning rows for trx.inv_amount from trxexpenses in subquery.
I want to show Expense_id with retruning rows using the above query.
ex)The result of the query is like that;
Expense_ Id project_id Ldate InvAmount RecogAmount MatAmount
5600 123 3/2/02 $100(InvAmount)
5600 432 3/12/02 $200(recogAmount)
5600 432 4/12/02 $250(MatAmount)
Thank you so much
Message was edited by:
user524064
Message was edited by:
user524064 -
Interactive report with single row select
Hi,
Is it possible to create an interactive report that has a single row select column i.e. you can only select one row and when you select another row it deselects any row selected before, simular to a list of values but with the functionionality of an IR report.
Thanks in advanceHi,
Try adding this to the query of your report:
select ...
apex_item.radiogroup(1, some_unique_column) sel
from ...You didn't say how you want to use this, but when the page is submitted the array apex_application.g_f01 may contain either none or exactly one element, which will be the some_unique_column value of the selected row.
Luis -
Merge multiple rows to get single row result
Hi,
Below is the sample data from my table USERINFO-
personid userid username orgid
1234 1235 TOM 1
2345 2346 HARRY 1
1111 2222 BOND 2
3333 4444 BERY 2
Now I want a query which can give me the following result-
personid userid username personid userid username orgid
1234 1235 TOM 2345 2346 HARRY 1
1111 2222 BOND 3333 4444 BERY 2
i.e., two records belonging to the same orgid should be merged into a single row resulset.
Please let me know the SQL query to get the desired result.
ThanksSQL> select * from test_otn;
PERSONID USERID USERNAME ORGID
1234 1235 TOM 1
2345 2346 HARRY 1
1111 2222 BOND 2
3333 4444 BERY 2
SQL> select max(decode(rn, 1, personid, null)) person_id1,
2 max(decode(rn, 2, personid, null)) person_id2,
3 max(decode(rn, 1, userid, null)) user_id1,
4 max(decode(rn, 2, userid, null)) user_id2,
5 max(decode(rn, 1, username, null)) username1,
6 max(decode(rn, 2, username, null)) username2,
7 orgid
8 from
9 (select row_number() over (partition by orgid order by orgid) rn,
10 personid, userid, username, orgid from test_otn)
11 group by orgid
12 /
PERSON_ID1 PERSON_ID2 USER_ID1 USER_ID2 USERNAME1 USERNAME2 ORGID
1234 2345 1235 2346 TOM HARRY 1
1111 3333 2222 4444 BOND BERY 2
Thx,
SriDHAR -
Discoverer 11g Workbook Fails With Single row subquery returns more than 1
All -
We are using discoverer-11g workbook using EBS 12.1.3 integration
We are seeing below error message only for few users on all workbooks in discoverer.
ORA-01427 Single row subquery returns more than one row
EBS Version : 12.1.3
Discoverer Version : 11.1.1.6
Database Version : 11.2.0.3
Please advise on this
Regards
VSHHi,
If it is happening for only a few users then the problem may be caused by security conditions built into the query. However, you need to give us some information about the SQL the workbooks are running. Do you get this error even for the very simple queries?
Rod West -
Join query with cfoutput group
Hi,
I have the problem with join query and output the goup by, can anyone helps please?
1: worked fine
<cfquery name="qOrgs" datasource="#GetDSN()#">
select org
from cat
</cfquery>
<cfoutput query="qOrgs" group="org">
#org#<br />
</cfoutput>
2: not work, not grouping and display duplicated.
<cfquery name="qOrgs" datasource="#GetDSN()#">
select org
from user u
inner JOIN cat c
on u.userid= c.userid
</cfquery>
<cfoutput query="qOrgs" group="org">
#org#<br />
</cfoutput>
ThanksTo expand on Dan's answer;
The "group" property of the <cfoutput...> tag is fairly simplistic. All it actuall does is conditionally output content whenever the value of the specified group column changes.
So if you do not use an ORDER BY clause in your SQL to group the values of that column together (or they don't naturally group because of the current state of the data in the database) then the output is probably not going to be as desired. -
Query with some rows I need in 1 row
I have this:
FK_Field1, Description
1..................A
1 ..B
2 ..A
1 ..C
3 ..E
3 ..G
And I need to do a query with this result:
FK_Field1, Description
1 ..A, B, C
2 ..A
3 ..E, G
How can I do it?????http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
-
Master/Detail in create mode with single row insert
Hi,
My jheadstart version is 10.1.3.2.52
I want to insert master and detail together on same page in create mode.
I have these settings:
- Master Layout: Form
- Detail Layout: Table
-"Single-Row Insert Allow" (Checked)
-"Single-Row Update Allow" (Checked)
-"Single-Row Delete Allow" (Checked)
-"Multi-Row Insert Allow" (unchecked)
-"Multi-Row Update Allow" (unchecked)
-"Multi-Row Delete Allow" (unchecked)
-"Show Add Row Button" (Checked)
When I Generate and run Application and click New Button, my detail table don't have any New Button.
Then I set "New Rows" to 1 for detail table and generate and run again, but problem still there!
Can you help me?
ThanksHi,
Thanks for your reply.
But I don't want multi-insert row be enabled(because of some logical reasons that forced by my scenario).
If I enable multi-insert row, even without "new row button" and just set "new row = 1", when user insert first row and click save button, one more empty row automatically add to detail table. I don't want this behavior. I want only one empty row for my detail table in create mode.
thanks again. -
Join Column with different rows, is it possible?
i would like to get a result fields
- Department ID
- total employee
- position under department
Query result A
Department ID | Total employee (under department)
DeptA | 123
Dept B | 222
Dept C | 0
Query result B
Department ID | position
DeptA | programmer
DeptA | lead programmer
DeptB | salesman
Dept C | CEO
Dept C | manager
Dept C | project manager
How can i get a result by joining two tables into one by using a single query?
Department ID | position | Total employee
DeptA | programmer | 123
DeptA | lead programmer | 123
DeptB | salesman | 222
Dept C | CEO | 0
Dept C | manager | 0
Dept C | project manager | 0
ThanksHi,
<p>
has it something to do with Need to write a POWERFUL Query. Need Help from MOST Advance Query Master?
</p> -
Table joining query with dates
Hello,
I have two tables, one containing a list of pupils, their class start date and their class end dates. The second table contains the address (postcode) history of the pupil. I need to bring these two tables together into one query to show all the classes from the 'pupils' table and add in the most recent postcode of the address prior to the start date of the clasS from the 'addresses' table. I.e. to show where the pupil lived when they started the class.
Could anyone show me how to do this please? I've provided a 'desired' table to show what I need the results to look like.
I hope this is clear, please ask if it isn't - I'm sure this should be simple! But I can't get my head around it. I'm using Oracle 9i and SQL Developer.
Thanks :)
select pupils.* from
(select 'A227' as pupil_id, to_date('21/04/2010','dd/mm/rrrr') class_start, to_date('21/09/2010','dd/mm/rrrr') class_end from dual union all
select 'A227' as pupil_id, to_date('08/08/2011','dd/mm/rrrr'), to_date('26/10/2011','dd/mm/rrrr') from dual ) pupils
select addresses.* from
(select 'A227' as pupil_id, to_date('20/04/2010','dd/mm/rrrr') address_start, null address_end, 'TW1 XVT' as postcode from dual union all
select 'A227' as pupil_id, to_date('03/08/2011','dd/mm/rrrr'), to_date('31/10/2011','dd/mm/rrrr'), 'TW3 ZE3' as postcode from dual union all
select 'A227' as pupil_id, to_date('01/11/2011','dd/mm/rrrr'), null, 'n23 4ty' as postcode from dual) addresses
select desired.* from
(select 'A227' as pupil_id, to_date('21/04/2010','dd/mm/rrrr') class_start, to_date('21/09/2010','dd/mm/rrrr') class_end, to_date('20/04/2011','dd/mm/rrrr') as address_start, 'TW1 XVT' as postcode from dual union all
select 'A227' as pupil_id, to_date('08/08/2011','dd/mm/rrrr') class_start, to_date('26/10/2011','dd/mm/rrrr') class_end, to_date('03/08/2011','dd/mm/rrrr') as address_start, 'TW3 ZE3' as postcode from dual) desired
Hi,
That's an example of a Top-N Query , and here's one way to do it:
WITH got_r_num AS
SELECT p.*
, a.address_start
, a.postcode
, ROW_NUMBER () OVER ( PARTITION BY p.pupil_id
, p.class_start
ORDER BY a.address_start DESC
) AS r_num
FROM pupils p
JOIN addresses a ON p.pupil_id = a.pupil_id
AND p.class_start >= a.address_start
SELECT pupil_id, class_start, class_end, address_start, postcode
FROM got_r_num
WHERE r_num = 1
;As you can see, the sib-query pairs each pupil and class with all the earlier addresses, and then numbers the addresses such that the latest address_start gets the lowest r_num (that is, 1, since ROW_NUMBER always starts with 1). The main query displays only the most recent address (the one with r_num = 1) for each pupil and class.
Does addresses.address_end plays any role in this problem? For example, would it matter if the most recent address for a given pupil and class had expired before the class started? That is, if we change the middle of address to:
select 'A227' as pupil_id
, to_date ('03/08/2011', 'dd/mm/rrrr')
, to_date ('07/08/2011', 'dd/mm/rrrr') -- Not 31/10/2011
, 'TW3 ZE3' as postcode
from dual would it still count as the last address before the class that started on 08/08/2011?
Edited by: Frank Kulash on Nov 1, 2011 11:36 AM
Added question about address_end -
How to write multi row sub query with the row containing range of values?
Hi all,
I have to include a column which contains weight ranges and it should come fom table called "report_range_parameters"
The following query will reutrn those weight ranges.
select report_parameter_min_value || ' -> ' || report_parameter_max_value
from report_range_parameters
WHERE report_range_parameters.report_parameter_id = 2359
and report_range_parameters.report_parameter_group = 'GVW_GROUP'
and report_range_parameters.report_parameter_name = 'GVW_NAME'
The below query should return the values group by those weight ranges.
How could I write that sub query?
select SUM(NVL("Class 0", 0)) "Class 0" ,
SUM(NVL("Class 1", 0)) "Class 1" ,
SUM(NVL("Class 2", 0)) "Class 2" ,
SUM(NVL(" ", 0)) "Total"
FROM (
SELECT report_data.bin_start_date_time start_date_time,
SUM(DECODE(report_data.gvw, 0, report_data.gvw_count, 0)) "Class 0" ,
SUM(DECODE(report_data.gvw, 1, report_data.gvw_count, 0)) "Class 1" ,
SUM(DECODE(report_data.gvw, 2, report_data.gvw_count, 0)) "Class 2" ,
SUM(NVL(report_data.gvw_count, 0)) " "
FROM report_data
GROUP BY report_data.bin_start_date_time
) results
RIGHT OUTER JOIN tmp_bin_periods
ON results.start_date_time >= tmp_bin_periods.bin_start_date_time
AND results.start_date_time < tmp_bin_periods.bin_end_date_time
GROUP BY tmp_bin_periods.bin_start_date_time,
tmp_bin_periods.bin_end_date_time Thanks.
Edited by: user10641405 on Jun 15, 2009 3:14 PM
Edited by: user10641405 on Jun 15, 2009 3:17 PMHi,
Assuming the following 4 things:
(1) report_range_parameters contains data like this, from your [previous thread|http://forums.oracle.com/forums/message.jspa?messageID=3541079#3541079]
id group name min_value max_value
1 gvw_group gvw_name 0 5
2 gvw_group gvw_name 5 10
3 gvw_group gvw_name 10 15(2) max_value is actually outside the range (that is, a value of exactly 5.000 is counted in the '5->10' range, not the '0->5' range)
(3) the range has to match some column x that is in one of the tables in your main query
(4) You want to add that column x to the GROUP BY clause
then you shopuld do somehting like this:
select SUM(NVL("Class 0", 0)) "Class 0" ,
SUM(NVL("Class 1", 0)) "Class 1" ,
SUM(NVL("Class 2", 0)) "Class 2" ,
SUM(NVL(" ", 0)) "Total"
, report_parameter_min_value || ' -> ' || report_parameter_max_value AS weight_range -- New
FROM (
SELECT report_data.bin_start_date_time start_date_time,
SUM(DECODE(report_data.gvw, 0, report_data.gvw_count, 0)) "Class 0" ,
SUM(DECODE(report_data.gvw, 1, report_data.gvw_count, 0)) "Class 1" ,
SUM(DECODE(report_data.gvw, 2, report_data.gvw_count, 0)) "Class 2" ,
SUM(NVL(report_data.gvw_count, 0)) " "
FROM report_data
GROUP BY report_data.bin_start_date_time
) results
RIGHT OUTER JOIN tmp_bin_periods
ON results.start_date_time >= tmp_bin_periods.bin_start_date_time
AND results.start_date_time < tmp_bin_periods.bin_end_date_time
LEFT OUTER JOIN report_range_parameters -- New
ON x >= report_parameter_min_value -- New
AND x < report_parameter_max_value -- New
AND report_range_parameters.report_parameter_id = 2359 -- New
and report_range_parameters.report_parameter_group = 'GVW_GROUP' -- New
and report_range_parameters.report_parameter_name = 'GVW_NAME' -- New
GROUP BY tmp_bin_periods.bin_start_date_time,
tmp_bin_periods.bin_end_date_time
, x -- New -
Hi all
I have two queries and i want to join this two query
The report column should be like this
item_number WK_30 WE_311st query
select
re.item_number,
nvl(le.quantity,0) - nvl(re.quantity,0) WK_30
from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
where le.item_number =re.item_number
and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+12nd query
select
re.item_number,
nvl(le.quantity,0) - nvl(re.quantity,0) WK_31
from BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
where le.item_number =re.item_number
and to_number(substr(re.year_week,-2,2)) = to_number(to_char(sysdate,'IW'))+2Thanks in advance
RegardsHello
It sounds like you need a cumulative sum, in which case I think you'll need to go with analytics. If you could supply create table statements, some sample data and a clear example of the output you expect, it would be easier to put something together. However, I think the statement below should work although it is untested.
SELECT
item_number,
plus_1,
plus_2,
plus_3,
plus_4,
plus_5,
plus_6,
plus_7,
plus_8,
plus_9,
plus_10,
plus_11,
plus_12,
plus_13
FROM
( select
re.item_number,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+1, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_1,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+2, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_2,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+3, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_3,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+4, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_4,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+5, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_5,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+6, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_6,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+7, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_7,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+8, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_8,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+9, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_9,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+10, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_10,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+11, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_11,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+12, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_12,
sum(decode (to_number(substr(re.year_week,-2,2)), to_number(to_char(sysdate,'IW'))+13, nvl(le.quantity,0) - nvl(re.quantity,0),0))
OVER( PARTITION BY re.item_number ORDER BY to_number(substr(re.year_week,-2,2)) PLUS_13,
ROW_NUMBER() OVER(PARTITION BY re.item_number) rn
from
BACKLOG_WEEK_WH_AFTR_ATP le, BACKLOG_ATP_GT_CW_IN re
where
le.item_number =re.item_number
and
and to_number(substr(re.year_week,-2,2)) in
( to_number(to_char(sysdate,'IW'))+1,
to_number(to_char(sysdate,'IW'))+2,
to_number(to_char(sysdate,'IW'))+3,
to_number(to_char(sysdate,'IW'))+4,
to_number(to_char(sysdate,'IW'))+5,
to_number(to_char(sysdate,'IW'))+6,
to_number(to_char(sysdate,'IW'))+7,
to_number(to_char(sysdate,'IW'))+8,
to_number(to_char(sysdate,'IW'))+9,
to_number(to_char(sysdate,'IW'))+10,
to_number(to_char(sysdate,'IW'))+11,
to_number(to_char(sysdate,'IW'))+12,
to_number(to_char(sysdate,'IW'))+13
WHERE
rn = 1HTH
David -
Email with single row accesing
how can send the email link to user for accessing particular document in IR report page?
i have email send plugin and sending email its working fine,but the email body ..
This is test message by DMS automated system.
<a href="http://localhost:7777/pls/apex/f?p=&APP_ID.:17:&SESSION.::&DEBUG.::::">Please click the link</a>
By,
DMS Development Team
when i open the email link its asking user name and password to normal user login page? but i need this user can accessing particular record only not rest of row!hai scott,
thank you for your guideline ,is it possible to pass the specific item based link? like
http://apex.oracle.com/pls/otn/f?p=19617:2:828113822039::NO:RP,2:P2_DOC_ID:1
the above email link will be open directly,ibecoz i enabled the security for this page is public! now how can set the link with 19617:2:828113822039::NO:RP,2:P2_DOC_ID:1 these values in email link?
Thanx,
Ram
Maybe you are looking for
-
How to change budget year in PO
Hi How to change budget year in PO Thanks Ajit
-
C7000 wireless printing set up says offline
I have my existing Phontosmart C7200, I have it connected to my network, but when I actually go to print from my laptops it says printer offline?? What do I need to do to complete this set up?
-
Tcode SU25 has been executed in Dev
Hello Gurus, The tcode SU25 has been executed one of our contractors in Development system (ECC 6.0). He executed the following steps: 1. step 2B. compare affected transactions 2. step 2C. Roles to be checked 3. Check indicator (Transaction SU24) I
-
When in editing mode I am getting occasional freezing and jerky playback but the sound track continues to run. The same in full playback The machine is a new 24" 3.06 so I doubt it is a lack of resource problem. Any advice would be appreciated.
-
General Precalculation Tab - Variable Assignment
Hi Experts!!! We have a new problem, we are setting Precalculation Web Application, the Data Provider query have a Variable, when we are setting this in the General Precalculation Tab a error ocurr "String of variables VAR_01 not filled" Number warn