Amount of effort from 2 different tables
Oracle Database 10 g Express Edition Release 10.2.0.1.0 - productI have the following tables
CREATE TABLE ADDPROJECT
( PROJID VARCHAR2(30) NOT NULL ENABLE,
PROJNAME VARCHAR2(30) ,
PROJSTARTDATE DATE,
PROJENDDATE DATE,
PARENTPROJID VARCHAR2(30),
PROJTYPE VARCHAR2(30),
PROJSTATUS VARCHAR2(30),
PRIMARY KEY (PROJID) ENABLE
)
CREATE TABLE ADDRESEARCHAREA
( RAID VARCHAR2(30) NOT NULL ENABLE,
RANAME VARCHAR2(30) ,
RASTARTDATE DATE,
RAENDDATE DATE,
PARENTRAID VARCHAR2(30),
RASTATUS VARCHAR2(30),
PRIMARY KEY (RAID) ENABLE
)
CREATE TABLE ALLOCATEASSOCIATES
( PROJID VARCHAR2(30) NOT NULL ENABLE,
ASSOCIATEID NUMBER(*,0) NOT NULL ENABLE,
ALLOCATIONSTARTDATE DATE,
ALLOCATIONPERCENT NUMBER(*,0),
ENDDATE DATE,
PRIMARY KEY (PROJID,ASSOCIATEID) ENABLE
)
CREATE TABLE PROJECTTORAASSOCIATION
( RAID VARCHAR2(30) NOT NULL ENABLE,
PROJID VARCHAR2(30) NOT NULL ENABLE,
STARTDATE DATE,
ENDDATE DATE,
STATUS VARCHAR2(30),
PRIMARY KEY (RAID,PROJID) ENABLE
)
CREATE TABLE PREVIOUSEFFORT
( PROJID VARCHAR2(30) NOT NULL ENABLE,
EFFORTPREVIOUS NUMBER(*,2),
PRIMARY KEY (PROJID) ENABLE
)
The PreviousEffort effort until March 31, 2012 (in person-months for various projects) and the AllocateAssociates allocation details associated with various projects from April 1, 2012 (effort in person months must be calculated using the date of beginning of allocation and assignment end date).Now, I'm writing a report that will add the effort of the two tables and generate a draft report of wise effort (in person-months adding the PreviousEffort and AllocateAssociates tables effort) for a given ResearchArea
I wrote the below query
SELECT to_char(SUM(nvl(pe.effortprevious,0)+nvl(EFFORT,0)),999.99 ) AS EFFORT,PROJECTID,PROJECTNAME,RAREAID,RAREANAME
FROM (
SELECT
(SUM
(MONTHS_BETWEEN(1+nvl(aa.enddate,sysdate),GREATEST(aa.allocationstartdate,to_date('04/01/2012','mm/dd/yyyy'))))
) AS EFFORT,
aa.projid AS PROJECTID,
ap.projname AS PROJECTNAME,
pr.raID AS RAREAID,
ar.raName AS RAREANAME
FROM allocateassociates aa,ProjecttoRAAssociation pr,addProject ap,AddResearchArea ar
WHERE pr.projid = aa.projid
AND aa.projid = ap.projid
AND pr.raid = ar.raid
GROUP BY aa.projid,ap.projname,pr.raid,ar.raname
)
, previouseffort pe
WHERE pe.projid = PROJECTID
GROUP BY PROJECTID,PROJECTNAME,RAREAID,RAREANAME
1 However, this query works very well if there is an entry for a project in the tables - PreviousEffort and AllocateAssociates. It does not work if there is no entry in one of the tables. For example: a project that started June 1, 2012 will not have an entry in the PreviousEffort table and therefore, get does not appear.2. by including the allocationpercent the computation of the effort, I get an error is NOT a GROUP BY
select (SUM
(MONTHS_BETWEEN(1+nvl(aa.enddate,sysdate),GREATEST(aa.allocationstartdate,to_date('04/01/2012','mm/dd/yyyy'))))
* aa.allocationpercent / 100
) AS EFFORT,
ORA-00979: not a GROUP BY expression
Can you please help to solve the two problems.Here are some insert commands.
insert into addproject values ('proj1','projname1',to_date('04/01/2012','mm/dd/yyyy'),'','','Research Project','Active')
insert into addproject values ('proj2','projname2',to_date('06/01/2012','mm/dd/yyyy'),'','','Research Project','Active')
insert into addproject values ('proj3','projname3',to_date('04/01/2012','mm/dd/yyyy'),'','','Research Project','Active')
insert into allocateassociates values ('proj1',1,to_date('04/01/2012','mm/dd/yyyy'),100,'')
insert into allocateassociates values ('proj1',2,to_date('04/01/2012','mm/dd/yyyy'),100,'')
insert into allocateassociates values ('proj3',3,to_date('04/01/2012','mm/dd/yyyy'),100,'')
insert into allocateassociates values ('proj2',4,to_date('06/01/2012','mm/dd/yyyy'),100,'')
insert into addresearcharea values ('ra1','raname1',to_date('04/01/2012','mm/dd/yyyy'),'','','Active')
insert into addresearcharea values ('ra2','raname2',to_date('04/01/2012','mm/dd/yyyy'),'','','Active')
insert into projecttoraassociation values ('ra1','proj1',to_date('04/01/2012','mm/dd/yyyy'),'','Active')
insert into projecttoraassociation values ('ra1','proj3',to_date('04/01/2012','mm/dd/yyyy'),'','Active')
insert into projecttoraassociation values ('ra2','proj2',to_date('04/01/2012','mm/dd/yyyy'),'','Active')
insert into previouseffort values ('proj1',120)
insert into previouseffort values ('proj3',10.5)
This?
SQL> SELECT to_char(SUM(nvl(pe.effortprevious,0)+nvl(EFFORT,0)),999.99 )
2 AS EFFORT,
3 PROJECTID,PROJECTNAME,RAREAID,RAREANAME
4 FROM (
5 SELECT
--"Corrected the misplaced paranthesis.."
6 (SUM
7 (MONTHS_BETWEEN(
8 1+nvl(aa.enddate,sysdate),
9 GREATEST(aa.allocationstartdate,
10 to_date('04/01/2012','mm/dd/yyyy')
11 )
12 )
13 * aa.allocationpercent / 100
14 )
15 ) AS EFFORT,
16 aa.projid AS PROJECTID,
17 ap.projname AS PROJECTNAME,
18 pr.raID AS RAREAID,
19 ar.raName AS RAREANAME
20 FROM allocateassociates aa,ProjecttoRAAssociation pr,
21 addProject ap,AddResearchArea ar
22 WHERE pr.projid = aa.projid
23 AND aa.projid = ap.projid
24 AND pr.raid = ar.raid
25 GROUP BY aa.projid,ap.projname,pr.raid,ar.raname
26 )
--"Added outer join"
27 full outer join previouseffort pe
28 on( pe.projid = PROJECTID)
29 GROUP BY PROJECTID,PROJECTNAME,RAREAID,RAREANAME;
EFFORT PROJECTID PROJECTNAME RAREAID RAREANAME
------- --------------- --------------- --------------- ---------------
16.62 proj3 projname3 ra1 raname1
132.24 proj1 projname1 ra1 raname1
4.12 proj2 projname2 ra2 raname2
Tags: Database
Similar Questions
-
To find common data in 2 columns from two different tables.
Hello
Could someone help me with a querry to discover common data of 2 columns from two different tables?
Thank you
RajeshTry as below.
select col1 ,col2 from tab1 intersect select col1 ,col2 from tab2;
-
I have the data into two table with the structure of similar column, I want to loop through the data in these two tables
based on some condition and runtime that I want to put the query in loop for example, the example is given, please help me
create table ab (a number, b varchar2 (20));
Insert into ab
Select rownum, rownum. "" sample "
of the double
connect by level < = 10
create table bc (a number, b varchar2 (20));
Insert into BC.
Select rownum + 1, rownum + 1 | "" sample "
of the double
connect by level < = 10
declare
l_statement varchar2 (2000);
Boolean bool;
Start
bool: = true;
If it is true, then
l_statement: =' select * ab ';
on the other
l_statement: =' select * from bc';
end if
I'm in execute immediate l_statement - something like that, but I don't know
loop
dbms_output.put_line (i.a);
end loop;
end;
Something like that, but this isn't a peace of the code work.
Try this and adapt according to your needs:
declare
l_statement varchar2 (2000);
c SYS_REFCURSOR;
l_a number;
l_b varchar2 (20);
Boolean bool;
Start
bool: = true;
If it is true, then
l_statement: = "select a, b, AB;
on the other
l_statement: = "select a, b from bc;
end if;
--
Open c for l_statement;
--
loop
extract the c in l_a, l_b;
When the output c % notfound;
dbms_output.put_line (l_a |') -' || l_b);
end loop;
close c;
end;
/
-
How to display the list item values both from 2 different tables?
Hello world.
I have a problem for the display of the data.
There are 2 tables in the database.
Table-1 has lc_value, lc_no, lc_dt, and vendor_code columns.
Table-2 has vendor_code, $vendor_name & vendor_address.
I created the form where I display data in list item 30 (tabular presentation - 30 records displayed).
I need to display all values automatically at the same time in the form just by clicking on "Enter_Query" and "Execute_Query".
It worked when the form had fields in a table in a single table.
I created fields in a table for tables; then created the relationship between the tables by using the join (vendor_code).
But when I run the form, click on "Enter_Query" and "Execute_Query", its does not work.
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production.
How can I do this?
Help me.
Thank you.
Dear Bruno,
Each provider code is to have a folder, then
Why keep two tables?
Why you want to update both the table at the same time?
Master / detail means,.
a master record depends on several detail records.
Please, understand and try to build your form with single table.
If you have already created 2 tables, then merge these into a single table.
Or other wise keep table_1 as a database block and to vend_name as a data field (element of database in the palette of the property is set to 'no').
Then go to the trigger of table_1 block post_query and write the following:
Select vend_name in: vend_name from vendor_mst where vend_cd =: lc_vend_cd;
In doing the above, the form will look as you wish but the change on the vend_name not to be saved because that is the point of no database.
Other than vend_name all fields in table_1 will be recorded.
Hope this will help.
Post edited by: Priyasagi
-
Process in two different tables in one page
Hi all
I have A form with a submit button, when I click on the button I want to send the data from two different tables. For example:
REQ_ID: 221
BOX_NUMBER: 2
NOM_ELEMENT: APPLE
COUNTRY_ORIGIN: USA
I want to send all the information in table 1 and only REQ_ID and BOX_NUMBER in table 2.
I tried to create processes two different which are:
1. the usual process line DML for table 1 and;
2. simple query 'Insert' SQL for table 2
It seems fine, until I realized that when the user tries to update the BOX_NUMBER to 10 for example, only 1 table is updated and table 2 creates an another duplicate data instead of updating the old one! This also applies to my button Delete,.
any idea to fix this problem?
Thank you very much
Vika
Reread what you wrote and you would realize why 2nd table only "new lines".
2. simple query "Insert into ' SQL for table 2
If you need to UPDATE the table, then you must write a simple UPDATE statement.
If you want to REMOVE from the table, then you must write a simple DELETE statement.
I call this "DML DIY" - do it yourself DML
(personally, I'd probably use MERGE for INSERT and UPDATE)
MK
-
extraction of unique records of registration of two different tables
Hello
In the following two tables different www.testing.com code exists in both tables. I want to compare two different columns from two different tables for unique records.
Thank you and best regardsSQL> select unique(videoLinks) from saVideos where sa_id=21; VIDEOLINKS ----------------------------------------------------------------------- www.testing.com SQL> ed Wrote file afiedt.buf 1* select unique(picLinks) from saImages where sa_id=21 SQL> / PICLINKS ----------------------------------------------------------------------- test test14 www.hello.com www.testing.com
Try
Select unique (videoLinks) in the saVideos where sa_id = 21
Union
Select unique (picLinks) in the saImages where sa_id = 21 -
Select values from the db1 table and insert into the DB2 table
Hello
I have three databases oracle running in three different machines. their ip address is different. among the DB can access databases. (means am able to select values and insert values into tables individually.)
I need to extract data from the DB1 table (ip say DB1 is 10.10.10.10 and the user is DB1user and the table is DB1user_table) and insert the values into DB2 table (say ip DB2 is 11.11.11.11 and the user is DB2user and table DB2user_table) of DB3 that is to have access to the two IPs DB.
How do I do this
Edited by: Aemunathan on February 10, 2010 23:12Depending on the amount of data must be moved between DB1 and DB2, and the frequency at which this should happen, you might consider the SQL * COPY more control. I think it's very useful for one-off tasks little, so I can live within its limits of the data type. More http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/apb.htm#i641251.
Change some parameter of sqlplus session are almost mandatory in order to get decent transfer rates. Tuning ARRAYSIZE and COPYCOMMIT can make a huge difference in flow. LONG change may be necessary, too, depending on your data. The documentation offers these notes on use:
To activate the copy of data between Oracle and databases non-Oracle, NUMBER of columns is replaced by DECIMAL columns in the destination table. Therefore, if you are copying between Oracle databases, a NUMBER column with no precision will become a DECIMAL column (38). When copying between Oracle databases, you must use SQL commands (CREATE TABLE AS and INSERTION), or you must make sure that your columns have a specified precision.
SQL * the VALUE LONGER variable limits the length of the LONG column you are copying. If all LONG columns contain data exceeds the value of LONG, COPY truncates the data.
SQL * Plus performs a validation at the end of each successful COPY. If you set the SQL * variable more COPYCOMMIT DEFINED to a value positive n, SQL * Plus performs a validation after copying all lots n of records. The SQL * Plus ARRAYSIZE variable SET determines the size of a batch.
Some operating environments require that the service names be placed between double quotes.
From a SQL * Plus term on DB3, can resemble the command to move all content from my_table in DB1 to the same table in DB2
COPY from user1/pass1@DB1 to user2/pass2@DB2 - INSERT INTO my_table - USING select * from my_table
Note the SQL code * more line-continuation character ' - '. It is used to escape the newline character in a SQL * Plus command if you do not have to type all on one line. I use it all the time with this command, but I can't locate the documentation on that right now. Maybe someone else can put their finger on it.
There are other ways to accomplish what the command copy and it is not without its quirks and limitations, but I find that there is usefulness in an Oracle Toolbox.
-
Select Max (Date) in two different tables...
Dear all,
I need the date of last update of two different tables, I mean max (date). We will update one table at a time. Updated once I need to take the last update.
It can be either in table A table B.
for example.
Table A
Date of the ID
100 16/05/2014
101 20/05/2014
102, 22/05/2014
Table B
Date of the ID
100 04/06/2014
101, 26/05/2014
102 21/05/2014
I need the date of table B (101 26/05/2014) last updated date...
Hello
Another way, using much more GRAND:
SELECT LARGER (max1, max2) x
FROM (SELECT MAX (mydate) max1
OF mytable_a
)
(SELECT MAX (myotherdate) max2
OF mytable_b
)
;
Best regards
Bruno Vroman.
-
Oracle how to multiply two columns of different tables and results
Oracle how to multiply two columns of different tables and get the result in the third column?
I want to multiply all the lines of the quantinty column in the table of quantity with the relevant lines of the table of prices price column and get the result of multiplying in the third column. What should I use procedure trigerr? OR IS IT POSSIBLE HOW TO DO IT PLEASE HELP :D
Edited by: 994229 2013-03-15 12:44/* Formatted on 3/15/2013 3:51:08 PM (QP5 v5.185.11230.41888) */ CREATE TABLE mytable1 AS (SELECT 1 id, 5 VALUE FROM DUAL UNION ALL SELECT 2, 7 FROM DUAL UNION ALL SELECT 3, 8 FROM DUAL); CREATE TABLE mytable2 AS (SELECT 1 id, 4 VALUE FROM DUAL UNION ALL SELECT 2, 12 FROM DUAL UNION ALL SELECT 10, 12 FROM DUAL); SELECT id, mytable1.VALUE, mytable2.VALUE, mytable1.VALUE * mytable2.VALUE product FROM mytable1 FULL OUTER JOIN mytable2 USING (id) ORDER BY id;
ID VALUE VALUE_1 PRODUCT 1 5 4 20 2 7 12 84 3 8 10 12
-
Get the number of lines to different tables on the same line
How can I get the number of lines for the different tables in a single line:
SELECT count (A), count (B), count (C) table tb_a A, tb_b B, tb_c C;
Thank you!Maybe if you want a little sophisticated look ;)
select * from (select 'a' tbl_name,count(*) cnt from table_a union all select 'b' tbl_name,count(*) cnt from table_b union all select 'c' tbl_name,count(*) cnt from table_c ) pivot (max(cnt) kount for tbl_name in ('a' as tbl_a,'b' as tbl_b,'c' as tbl_c))
Concerning
Etbin
-
Variable from PL/SQL table?
Hello
I need to process some data in PL/SQL.
The first thing I would do, is to write a query that collects all the mydata from different tables in exactly one table on which I can make simple queries.
What is the preferred way to do this?
Temporary table, or view, or something else?
I would preffer not not to create the physical table for this. I want to use only a PL/SQL variable.
Thank youuser610868 wrote:
HelloThanks for your advice, but I would still do it.
Is it possible or not? (fully searchable custom table in a PL/SQL variable)Yes and no.
Yes, it is possible to get all your data and put it in a PL/SQL 'table' (better known as an array or a collection, because they are not tables)
No, you will not be able to 'interrogate' the data in this array/collection, simply because there isn't a table, and SQL will not work against it.You can do all kinds of PL/SQL code to process the data in the table or the collection to simulate what would do SQL, but it will be several times slower than that of SQL, and to be honest, no expert here is likely to give you code to do because it's just the wrong way to do things.
If you can give a legitimate situation where you needed to load the data in a table or the collection in order to treat it, then of course someone can show you how to do this, but it is likely that most of the situations describe you would be better made using SQL tables from database etc..
-
How to find the same column name in different tables in the same schema
Hello
I find the 'ename' column name in different tables in the same schema.
Thank you
NrHello
Try this query
Select column_name, table_name from user_tab_columns where column_name = 'ENAME ';
Award points and end the debate, if your question is answered or mark if she was...
Kind regards
Lacouture.
-
Select cursor for update: multiple columns of different tables
Hello
I have two tables test1 and test2. I want to udpate the column (DEPT_DSCR) from the TEST1 and TEST2 using select for update and current tables of the... with the cursor.
I have a code drafted as follows:
DECLARE
v_mydept1 TEST1. TYPE % DEPT_CD;
v_mydept2 TEST2. TYPE % DEPT_CD;
CURSOR C1 IS SELECT TEST1. DEPT_CD, TEST2. DEPT_CD OF TEST1, TEST2 WHERE TEST1. DEPT_CD = TEST2. DEPT_CD AND TEST1. DEPT_CD IS 'AA' FOR THE UPDATE OF TEST1. DEPT_DSCR, TEST2. DEPT_DSCR;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO v_mydept1, v_mydept2;
WHEN EXIT C1% NOTFOUND;
UPDATE TEST1 SET DEPT_DSCR IS "PLSQL1" WHERE CURRENT OF C1;.
SETTING A DAY TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1.
END LOOP;
COMMIT;
END;
The code above when it is run, declares that it runs successfully. But it does not update the columns you want [DEPT_DSCR].
It works only when we want to update one or more columns of the same table... i. e by providing these columns after ' to UPDATE THE.
I don't know what exactly is the problem when you want to update several columns of different tables.
Can someone help me on this?user12944938 wrote:
But it's more the notion of compensation and understanding.See the link below:
http://download.Oracle.com/docs/CD/B10501_01/AppDev.920/a97269/pc_06sql.htmSee the section RESTRICTION in the link above.
Twinkle
-
Display and update of fields in different tables on the same page.
I am facing two problems...
(1) I have a report on which I show several fields of 4 different tables. For each row of data, there is a link to change on the first column. By clicking on the link change, I show you a form where I want to show the respective data. On the link change, even if I send you the data in the report, they do not appear on the form (what edit link is clicked). Also, there is only room for 3 items to ship through the link change.
How to display the data correctly on the form? Is there another way to use the link change?
(2) on the form, how do I update the data from different tables?
Thank you
GargiHi Lisa,
The text of presentation on the INSTEAD OF triggers is in: [http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7004.htm#sthref7918]
First of all, your SQL View contains a unique key so that your triggers and the two Apex know what is updated.
Then, you can create instead of triggers for "instead of INSERT ON viewname", 'instead of UPDATE ON viewname' and 'DELETE ON viewname' on your SQL view. What do these triggers depends on what you need. In the trigger code, you refer to new data using: NEW.column_name and old data using: OLD.column_name (updates both: OLD and: NEW values).
I'm not sure of the SEPARATE, the GROUP IN question. You would certainly have a unique key on each record. It could be that the DISTINCT or GROUP BY clause will have to be taken out of the SQL view and is part of the source of the region, so that the SQL view does nothing with the data other than to join several tables in a single "table" from the Primary Key/Foreign Key relationship.
Andy
-
Create one of 2 different tables tables
Hello
How do I create a table of 2 different tables. The source tables have given and I want to include in the new table.
I have try this:
create the table NEW_ONE
Select * from OLD_ONE
Union
Select * from OLD_ONE2;
But it did not work properly :/Perhaps mean you this? Don't know what your join condition is?
create table NEW_ONE as
Select o1.id_oo, o1.name_oo, o2.id_002, o2.name_oo2
of old_one o1, o2 old_one2
where o1.id_oo = o2.id_oo2; -PLEASE CHECK THIS JOIN CONDITION
Maybe you are looking for
-
Re: Tecra S11 - sometimes WLAN simply disconnect
Hello I have a problem with my WiFi. Sometimes my Wlan disconnect the current signal and who says there where no connection available. When I go in my control panel and turn off the Wlan and back on everything works fine again. Sometimes it does is a
-
Microsoft abandoned the plan to release the local deployment of Hadoop Isotope for Windows?
The link http://social.technet.microsoft.com/wiki/contents/articles/6218.getting-started-with-hadoop-based-services-for-windows-en-us.aspx indicates references to installation on site barred. Can you get it someone please let me know if Microsoft has
-
Access to the hotmail account.
Hello, I have a problem loging on my hotmail account, also I have the associated account cannot access due to a similar error. How can I send the password to reset the link to an account not associated with an e-mail account.
-
can I move itunes and music on external drive
100 GB to 150 GB is used by the music and itunes.my internal hard drive is full and I can't put any CD on my computer.i news bought an external 640 GB goflex thinking that this would add to my disk space but it only supported everything.since she is
-
HP Photosmart C309a does not print on wlan
Photosmart C309a is about 1.5 years old. Since a few days it prints no more on wlan, printing by port USB is fine. All other devices communicate very well on the router. I tried to set up the printer, but it does not detect a router (let the search f