How to create a view with columns from multiple rows
I have posted this in SQL/PSL forum, but I hope database experts in this group can give me ideas too, also the need is from BI reports.
I have a table, say, project_milestones, which has these columns in concern:
proj_id, milestone_name, actual_end_date
with data:
proj_id, milestone_name, actual_end_date
===== ================ ==============
1001, Key Element Approve, 2009-10-02
1001, Final Synopsis, 2009-10-07
1001, Final Protocol Approved, 2009-10-15
1001, FPFV, 2010-01-10
1001, LPFV, 2010-03-12
1002, Key Element Approve, 2008-12-02
1002, Final Synopsis, 2009-01-07
1002, Final Protocol Approved, 2009-01-12
1002, FPFV, 2009-03-30
1002, LPFV, 2009-10-04
There are about 10 milestones in each project.
I have to create a view to flat these data at project level, looks like this:
proj_id, key_element_date, final_synopsis_date, final_protocol_approved_date, FPFV_date, LPFV_date, key_element_to_final_synopsis_days, final_synopsis_final_protocol_days, ....
How can I do this?
Thanks,
user9175541 wrote:
I have posted this in SQL/PSL forum, but I hope database experts in this group can give me ideas too, also the need is from BI reports.
I have a table, say, project_milestones, which has these columns in concern:
proj_id, milestone_name, actual_end_date
with data:
proj_id, milestone_name, actual_end_date
===== ================ ==============
1001, Key Element Approve, 2009-10-02
1001, Final Synopsis, 2009-10-07
1001, Final Protocol Approved, 2009-10-15
1001, FPFV, 2010-01-10
1001, LPFV, 2010-03-12
1002, Key Element Approve, 2008-12-02
1002, Final Synopsis, 2009-01-07
1002, Final Protocol Approved, 2009-01-12
1002, FPFV, 2009-03-30
1002, LPFV, 2009-10-04
There are about 10 milestones in each project.
I have to create a view to flat these data at project level, looks like this:
proj_id, key_element_date, final_synopsis_date, final_protocol_approved_date, FPFV_date, LPFV_date, key_element_to_final_synopsis_days, final_synopsis_final_protocol_days, ....
How can I do this?
Thanks,Create a pivot table and put "milestone_name" in the Columns section under the Labels.
Put "actual_end_date" in the Measures section and change the Aggregation Rule to "Max."
The rest of the attributes keep in Rows section.
Similar Messages
-
How to create a view indicating column's length?
SQL>create table abc (a number(12));
I want to create a view cde with a length of number(5) by "describe cde" in sql*plus.
SQL>create view cde(a) as select a from abc;
SQL>desc cde
A NUMBER(12)
how to create a view indicating column's length? the actual value in abc only <1000
I want to create a view cde with a length of number(5) .
SQL>desc cde
A NUMBER(12)
Thank You
Ming-An ZhangThis does not make sense. How can a view be a NUMBER(5) and the actual column a NUMBER(12)?
What happens if there is a 10 or 12 digit number in the table? Just what is the view suppose to do? Crash and burn? Where is the logic in that?!
If the table's column has an incorrect precision and size, THEN FIX IT!! Do not hack it with view!
It is silly purposefully building constructs into the database that can easily result in run-time errors. -
How to create a interface with NTR from SAP XI?
How to create a interface with NTR from SAP XI?
Hi,
What do you mean by NTR ?...
What are the details you needed...Please be clear and more elaborative as far as possible..so that you will get straight forward answers...
HTH
Rajesh -
Problem creating a datablock with columns from 2 tables...
Hello guys, i have a problem in creating a datablock with columns from 2 different tables. I try to create the datalock manually and in the Query Data Source Type Property i choose FROM clause query, and in the query data source name property i type my sql statement with the columns i want to display.After that i place the items that the datablock will contain , manually from the painter. However , when i run the application, the datablock doesn't display the items from the database. Am i doing something wrong?
Thanx in advance,
Regards,
Bill.Never mind Peter, I found the error. I forgot to make execute_query for the datablock, so this was the reason why the items weren't displayed to me.
Thanx anyway a lot for your advices and your time you spent ! -
How to create table view with reference table
Hi experts,
How to create table view with reference table in SE11, plz gve me stp by stp procedure.
pints grnded for hlp.Hi
Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
enter the description
On the left hand side choose the table name.
Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
Save and then activate.
Hope this helps.
Regards,
Harish -
How to create a view with a column of counts of the occurence of values
If my table is:
ID
1
2
3
3
5
5
5
I want to create a view with the following result:
ID COUNT
1 1
2 1
3 2
5 3
How would I accomplish this?Sorry, my mistake. I was thinking about counting distinct events.
I created a table with your example values:
You should do a projection with a calculated column = 1:
And then add this calculated column as an aggregated measure on the aggregation node:
Result:
Cheers,
Fernando -
How to create a view with parameters; read the documentation but nothing!
Hello!
I'm new to the Oracle world but together with my coworkers we need to very quickly study Oracle to figure out whether we'll add Oracle to our list of supported databases or not.
Question: How do I create a view with parameters?
I've read the documentation but I could not find this! I found the sql syntax to create a view but no parameters whatsoever...
I have found on the web some very complicated way of doing this, but doesn't Oracle support Views with parameters?
The goal here is to return a recordset, don't forget, so,please don't speak about stored procedures unless you are going to tell me how to get a recordset out of a stored procedure! ;)
Thanks for all your help and attention!
Jorge C.You can set up a parameterized view via context as follows:
1. Set up a procedure to set your context values:
create or replace procedure p_set_context (p_context IN VARCHAR2,p_param_name IN VARCHAR2,p_value IN VARCHAR2)
as
BEGIN
sys.dbms_session.set_context(p_context,p_param_name,p_value);
END;
2. Create your context using the procedure you just created
create or replace context my_ctx using p_set_context
3. This is the test table I'll use
create table my_table(col1 number)
and populate it:
begin
for v_index in 1..10
loop
insert into my_table values(v_index);
end loop;
end;
and the view that will be parameterised
create or replace view v_my_table as select col1 from my_table where col1 between sys_context('my_ctx','start_range') and sys_context('my_ctx','end_range')
4. Now set the parameters using the procedure above.
begin
p_set_context('my_ctx','start_range','1');
p_set_context('my_ctx','end_range','5');
end;
5. Selecting from my_table will give you 1 to 10 (no surprise there :-) )
selectng from v_my_table will give you 1 to 5
You can use the context to set formats etc using the same principle. A common gotcha to watch for is trying to set the context directly using DBMS_SESSION.SET_CONTEXT instead of creating a procedure. This belongs to SYS and SYS won't have the privileges to set your context so you get an insufficient privileges result leading to much headscratching and unnecessary grants (at least that's my understanding of it).
Sorry Jorge, as you're new to Oracle I should also have pointed out for completeness sake, that you can change the parameters at any time through recalling the p_set_context, for example, following on from above, after your "select * from v_my_table" and seeing 1 to 5, you could then do
begin
p_set_context('my_ctx','start_range','3');
end;
and when you requery 'Select * from v_my_table' you will now see rows 3 to 5.
Bit of a simplistic example, but you can see how easy it is. :-)
Message was edited by:
ian512 -
How to create a view with Oracle apps Org initialization ?
Hi,
How to create a view which needs Oracle apps org initialization to provide the correct data .
The purpose of the view is to be accessed in Primavera DB via a DB link for reporting purpose.
So how should the org be initialized so that the view returns the correct data when accessed from the remote data base using the DB link?
EX: step1 run fnd_client_info.set_org_context for the org
step2 query the veiw returns correct data in Oracle.
How can this be achieved if the view needs to be accessed via DB link?
sample view sql :
select po_header_id
from po_distributions_all pod
where (apps.po_intg_document_funds_grp.get_active_encumbrance_func
('PO',
pod.po_distribution_id
) <> 0
Thanks in advance!
DarshiniHi,
This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
Hope this helps...
Regards,
Ganesh R -
How to create a view with parameter?
who can tell me hwo to create a view with
parameters just like a cursor?Hi,
This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
Hope this helps...
Regards,
Ganesh R -
How To Create Table View With Same Column name But Different Table?
Hi All,
I have the problem to create a tableview with same column name but in different table.
The Table that i have:-
Table - PAC051MPROFORMA
Column - mrn,visitid
Table - PAC051TPROFORMA
Column - mrn,visitid
Table - PAC052MTRANSBILL
Column - mrn,visitid
Then i want to create a table view to view that table. This is my SQL
CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
where
*(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
and
*(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
That SQL Return this error = ORA-00957: duplicate column name
Then I modify that SQL to
CREATE VIEW pacviewproforma (mrn,visitid)
As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
where
*(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
and
*(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
This time this error return = ORA-01730: invalid number of column names specified
What should i do?
Thanks...Hi,
SQL> CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
2 As Select
3 PAC051MPROFORMA.mrn,
4 PAC051MPROFORMA.visitid,
5 PAC051TPROFORMA.mrn,
6 PAC051TPROFORMA.visitid,
7 PAC052MTRANSBILL.mrn,
8 PAC052MTRANSBILL.visitid
9 from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
10 where
11 (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
12 and
13 (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
ERROR at line 1:
ORA-00957: duplicate column namePlease give different names to each column.
Something like this..
SQL> CREATE OR REPLACE VIEW pacviewproforma (MPROFORMA_mrn,MPROFORMA_visitid,TPROFORMA_mrn,TPROFORMA
_visitid,MTRANSBILL_mrn,MTRANSBILL_visitid)
2 As Select
3 PAC051MPROFORMA.mrn,
4 PAC051MPROFORMA.visitid,
5 PAC051TPROFORMA.mrn,
6 PAC051TPROFORMA.visitid,
7 PAC052MTRANSBILL.mrn,
8 PAC052MTRANSBILL.visitid
9 from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
10 where
11 (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
12 and
13 (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
View created.
SQL> DESC pacviewproforma;
Name Null? Type
MPROFORMA_MRN NUMBER
MPROFORMA_VISITID NUMBER
TPROFORMA_MRN NUMBER
TPROFORMA_VISITID NUMBER
MTRANSBILL_MRN NUMBER
MTRANSBILL_VISITID NUMBER
ORA-01730: invalid number of column names specifiedThe list of column nmae you specified during the CREATE VIEW should match with the SELECT list of the view.
Twinkle -
Numbers: How to create a spreadsheet with columns
I would appreciate help with something which seems quite basic, but I cannot figure it out from the manual. I need to track invoices. I would like columns with invoice number, supplier`s name, dates, and then of course numbers. I cannot see how to change a column (in blank spreadsheet) labelled as `A` to `invoice number`, for example. I am truly in the wilderness when it comes to spreadsheets! Thank you.
vista4444,
Welcome to Numbers. Spreadsheets (or "tables" as they are refered to in Numbers) will always show columns headed A, B, C, etc. What you want to do is type your labels in the first row (header row) under those letters. Similarly, the A column is a header column for the rows. These headers have a special function: they are used to name rows and columns and cannot contain formulas. If using formulas in other cells, columns can be identified by either letter or name in the header below. The same is true for rows.
You will know when the these headers are active when you see them shaded over near the far right of the format bar under the media icon.
pw -
How to create a view with "WITH CLAUSE"
Hi,
I have a query with "WITH" CLAUSE , I need to create a view on this query. But I am getting error like
ORA-32034 : Unsupported sue of WITH clause.
Please help me...!!
Please find below my query...!!
WITH RANGE
AS (SELECT A.MASTERMACHINEID,
a.startdate,
a.enddate,
a.startdate - (1 / 3) + (lvl) * 1 / 3 SHIFT_ST_DT,
a.startdate + (lvl) * 1 / 3 AS SHIFT_END_DT,
a.quantity,
(LEAST ( enddate, TODATE) - GREATEST ( FROMDATE, startdate)) * 24 TOTAL_HRS,
(enddate - startdate) * 24 AVAIL,
todate,
fromdate
FROM OMP A,
(SELECT LEVEL lvl
FROM (SELECT MAX (enddate - startdate) AS diff FROM OMPWORKORDER)
CONNECT BY LEVEL <= (diff) * 3),
MASTER B
WHERE A.MASTERMACHINEID = B.MASTERMACHINEID
AND lvl / 3 <=(enddate - startdate) + 1
ORDER BY SHIFT_ST_DT)
SELECT shift_date,
shift_num,
shift_hrs,
DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME),
8 - DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME) shift_avail_hrs,
qty,
total_qty
FROM (SELECT TRUNC (SHIFT_ST_DT) shift_date,
ROW_NUMBER () OVER (PARTITION BY TRUNC (SHIFT_ST_DT) ORDER BY SHIFT_ST_DT) shift_num,
8 shift_hrs,
(LEAST ( SHIFT_END_DT, TODATE) - GREATEST ( FROMDATE, SHIFT_ST_DT)) * 24
SHUT_DWN_TIME,
quantity / (avail - TOTAL_HRS) qty,
round(((SHIFT_END_DT - SHIFT_ST_DT) * 24 - (LEAST (SHIFT_END_DT, TODATE) - GREATEST (FROMDATE, SHIFT_ST_DT)) * 24) * QuantiTY / (AVAIL - TOTAL_HRS),2)
TOTAL_QTY
FROM RANGE A );Regards
KPR
Edited by: BluShadow on 17-Mar-2011 09:48
added {noformat}{noformat} tags for readabilityTry creating view on following query, if it can help you:
SELECT shift_date,
shift_num,
shift_hrs,
decode(SIGN(shut_dwn_time), -1, 0, shut_dwn_time),
8 -decode(SIGN(shut_dwn_time), -1, 0, shut_dwn_time) shift_avail_hrs,
qty,
total_qty
FROM
SELECT TRUNC(shift_st_dt) shift_date,
row_number() over(PARTITION BY TRUNC(shift_st_dt)
ORDER BY shift_st_dt) shift_num,
8 shift_hrs,
(least(shift_end_dt, todate) -greatest(fromdate, shift_st_dt)) *24 shut_dwn_time,
quantity /(avail -total_hrs) qty,
ROUND(((shift_end_dt -shift_st_dt) *24 -(least(shift_end_dt, todate) -greatest(fromdate, shift_st_dt)) *24) *quantity /(avail -total_hrs), 2) total_qty
FROM
SELECT a.mastermachineid,
a.startdate,
a.enddate,
a.startdate -(1 / 3) +(lvl) *1 / 3 shift_st_dt,
a.startdate +(lvl) *1 / 3 AS
shift_end_dt,
a.quantity,
(least(enddate, todate) -greatest(fromdate, startdate)) *24 total_hrs,
(enddate -startdate) *24 avail,
todate,
fromdate
FROM omp a,
(SELECT LEVEL lvl
FROM
(SELECT MAX(enddate -startdate) AS
diff
FROM ompworkorder)
CONNECT BY LEVEL <=(diff) *3),
master b
WHERE a.mastermachineid = b.mastermachineid
AND lvl / 3 <=(enddate -startdate) + 1
ORDER BY shift_st_dt
) a
;Regards,
Dipali.l -
Create a view with datatype from dual
I have Windows XP with 10g 10.2.0.1.0
I need to create a view from dual and with data type, such as NUMBER(5,2), NUMBER or VARCHAR2(20) .
such as:
create view test(view_test varchar2(20)) as (select view_test from dual)
Please help. Thanks in advance.It does seem kind of odd, but you can do something like this with the CAST function:
SQL> create view dual_view as
2 select cast(null as number(5,2)) col1
3 ,cast(null as date) col2
4 ,cast(null as varchar2(30)) col3
5 from dual;
View created.
SQL> desc dual_view
Name Null? Type
COL1 NUMBER(5,2)
COL2 DATE
COL3 VARCHAR2(30)I used NULLs but you can use actual values if you want. -
How to create materialized view with parameter and index ?
Hi all,
i am using oracle 11g.
i want to create parameter materialized view with two parameter (STORED_VALUE, LOV_NAME) with an index .
i have below view
CREATE OR REPLACE FORCE VIEW SR_MY_TEST(DISPLAYED_VALUE, STORED_VALUE, LOV_NAME) AS
SELECT DISPLAYED_VALUE , LOVVALUE.STORED_VALUE , lovname.lov_name
FROM (SELECT T.LOV_VALUE_ID,
T.LOV_ID,
T.ORG_ENTITY_ID,
T.STORED_VALUE,
T.DISPLAYED_VALUE,
T.ENTERPRISE_ID
FROM MS_QS_LIST_OF_VALUES_T T) lovvalue, ms_qs_lov_names lovname
WHERE lovvalue.lov_id = lovname.lov_id
AND lovvalue.org_entity_id = 1
and LOVVALUE.ENTERPRISE_ID = 100000
AND LOVNAME.ENTERPRISE_ID = 100000;
i want to create index on STORED_VALUE, LOV_NAME
Thanks
DambyNo.AFAIK, there's nothing called as "parameterized MV".
Materialized View store data like tables (and not like Views). So, does it make sense when you say - "table with parameters" ?
Could you please explain your business requirement?
What is the purpose behind those 2 parameters? -
How to get the value of column from previous row to current row?
Hi All,
I am facing a critical problem in SQL query (for reporting purpose (COGNOS)). please reply to my query.
REQUIREMENT: i want to retrive value of a column (this is not a table column, this will be calculated based expression) from previous row to current row.
EXAMPLE:
TABLE NAME: i have to join multiple tables. so, i am not mentioning table names here.
DISPLAY COLUMNS in the report: item, loc, sku, beginval (not table column), endval (not table column, this will calculated based on some expressions), etc. Here, first time the value of BEGINVAL will be taken from some x column name of x table. ENDVAL will calculated based on the expression. For the next row onwards, BEGINVAL will become the value of ENDVAL and the value of ENDVAL will be calculated based on the expression and this expression uses the value of BEGINVAL.
my report will look like below.
ITEM LOC SKU BEGINVAL ENDVAL
1 HYD 1-HYD 10 10+1+2 (13)
2 HYD 2-HYD 13 13+1+2 (16)
3 SEC 3-SEC 16 16+1+2 (19)
4 SEC 4-SEC 19 19+1+2 (22)
etc....
in the above output, BEGINVAL and ENDVAL columns are not part of any table. they are alias column names.if you observe intially BEGINVAL will be assigned to some value, but from subsequent rows, BEGINVAL will become the ENDVAL of previous row.
Please help me on how to write this query?Hi, please find the detail description of the problom.
DDL (table scripts)
ITEM
CREATE TABLE ITEM
ITEM VARCHAR2(50 CHAR) NOT NULL,
DESCR VARCHAR2(50 CHAR) DEFAULT ' ' NOT NULL,
UOM VARCHAR2(50 CHAR)
SKU
CREATE TABLE SKU
ITEM VARCHAR2(50 CHAR) NOT NULL,
LOC VARCHAR2(50 CHAR) NOT NULL,
OH float
SKUPROJSTATIC
CREATE TABLE SKUPROJSTATIC
ITEM VARCHAR2(50 CHAR) NOT NULL,
LOC VARCHAR2(50 CHAR) NOT NULL,
STARTDATE DATE
VehicleLoad
CREATE TABLE VEHICLELOAD
LOADID VARCHAR2(50 CHAR) NOT NULL,
DESCR VARCHAR2(50 CHAR) DEFAULT ' ' NOT NULL,
SHIPDATE DATE DEFAULT TO_DATE('01/01/1970','MM/DD/YYYY') NOT NULL,
ARRIVDATE DATE
VEHICLELOADLINE
CREATE TABLE VEHICLELOADLINE
LOADID VARCHAR2(50 CHAR) NOT NULL,
ITEM VARCHAR2(50 CHAR) NOT NULL,
QTY float(126)
DML scripts
I can't provide the the DML scripts, because its very huge data.
Main QUERY is below.
below is the query which i have to write and execute.
select
i.item,
i.descr,
i.unitsperpallet,
sp.loc,
sp.startdate,
'Crucial_IND',
LAG (EndBal,1,0) OVER (ORDER BY STARTDATE) BeginBal,
SP.FCSTCUSTORDERS CustOrders,
SP.COMMITINTRANSOUT,
SP.RECARRIV,
SP.TOTINTRANSIN,
(BeginBal - sp.FCSTCUSTORDERS - sp.COMMITINTRANSOUT + sp.TOTINTRANSIN ) EndBal,
'CuttingQty',
VLL.QTY,
vl.source,
vl.arrivdate,
vl.shipdate,
vl.loadid,
s.oh
from item i, skuprojstatic sp, sku s, VehicleLoad vl, VehicleLoadLine vll
where sp.item = i.item
and s.item=i.item
and sp.item =s.item (+)
and sp.loc = s.loc (+)
and vll.item = s.item
and vll.loadid = vl.loadid
and to_char(sp.startdate ,'mm/dd/yyyy') = to_char(vl.arrivdate,'mm/dd/yyyy')
and sp.loc = vl.dest (+)
order by sp.startdate
problem description: in the above query, BeginBal and EndBal is what i am looking for. when i execute this query, oracle throwing an error saying that alias names can't be used as expressions. For the first row, the BeginBal should be the value sku.OH and for the subsequent rows, this value will be the previous row value of EndBal.
Maybe you are looking for
-
I need to connect to my work PC remotely from my macbook. I think I need the citrix software. But which version and what is the procedure?
-
Hi, I have a 3 user decision steps in my Customised workflow which uses the task TS00008267. Each task has different decison text and outcome. When this is executed through UWl the outcome does not appear as they are in SBWP. Does this need and Porta
-
Actually the requirement is to display Error message in selection screen ,but it should display like(Red triangle inside exclamatory mark). warning message is displayed with yellow color but that is not needed for this. kindly help..tks in advance
-
Foreign Exchange on Report Painter Report
I've been asked to create a Balance Sheet and P&L that have the G/L Accounts down the right hand side while across the top each column is a new company code. I am working on building this report in Report Painter. In each column I have no problem
-
Hello every body, I have a trouble with downloding a file with APEX4.1. Wel , i have a table width this structure MY_TABLE(ID NUMBER(5),NAME VARCHAR2(100),BLOB_CONTENT Blob). i can upload file information into this table but when i try to download th