Obtain info from nested table in function?
Oracle9i 9.2.0.1.0/Windows 2000
I'd like to obtain an ID from a nested table object in order to insert it into an ID field (outside the nested table I'm getting it from). I've got a function that lets me get a foreign key ID from one other table ('objtarget'); but it isn't nested:
CREATE FUNCTION oeln.get_obj_id(
obj_type IN oeln.objtarget.objecttarget%type
RETURN oeln.objtarget.obj_id%type
IS id_type oeln.objtarget.obj_id%type;
BEGIN
SELECT obj_id INTO id_type
FROM oeln.objtarget
WHERE oeln.objtarget.objecttarget = obj_type;
RETURN(id_type);
END;
SELECT obj_id
FROM oeln.objtarget
WHERE obj_id = get_obj_id('');
I'm getting compilation errors on functions to obtain ID's from nested tables instead. I've got the table 'opt' (includes the fields 'opt_id' & 'optics'). The 'optics' field in opt is of type o_tab(o_ty), including the field 'optinfo'. I'd like to get the opt_id out of the opt table, from input I obtain for the optinfo field: i.e.,
SELECT opt_id
FROM oeln.opt
WHERE opt_id = get_opt_id('');
In other words, I'd like to get opt_id from the opt table like I get obj_id from the objtarget table; but instead of looking it up by objecttarget I've got to look it up by optinfo, a field in a nested table object in the opt table itself. I've only gotten compilation errors on functions in order to do this. Is this an option?
- Noel
select * from table(v_names);
I guess ,here you were trying to put the content of the NT into another NT, or just trying to print it.
But, I don't think INTO Clause is mandatory here.
Please check your modified code (w/o INTO) and the output :
DECLARE
TYPE string_table IS TABLE OF VARCHAR (100);
v_names string_table := string_table ();
v_test string_table := string_table ();
BEGIN
v_names.EXTEND (3);
v_names (1) := 'name1';
v_names (2) := 'name2';
v_names (3) := 'name3';
DBMS_OUTPUT.put_line ('Old collection - '||v_names (1));
DBMS_OUTPUT.put_line ('Old collection - '||v_names (2));
DBMS_OUTPUT.put_line ('Old collection - '||v_names (3));
DBMS_OUTPUT.put_line ('Old collection - '||v_names.COUNT ());
DBMS_OUTPUT.put_line (CHR(10));
/* SELECT * FROM TABLE (v_names); */
v_test := v_names;
DBMS_OUTPUT.put_line ('New collection -- '||v_test (1));
DBMS_OUTPUT.put_line ('New collection -- '||v_test (2));
DBMS_OUTPUT.put_line ('New collection -- '||v_test (3));
DBMS_OUTPUT.put_line ('New collection -- '||v_test.COUNT ());
DBMS_OUTPUT.put_line (CHR(10));
/* Printing using FOR LOOP */
FOR i IN v_test.FIRST..v_test.LAST
LOOP
DBMS_OUTPUT.put_line ('In FOR Loop --- '||v_test (i));
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error ' ||SQLERRM|| DBMS_UTILITY.format_error_backtrace);
END;gives o/p :
Old collection - name1
Old collection - name2
Old collection - name3
Old collection - 3
New collection -- name1
New collection -- name2
New collection -- name3
New collection -- 3
In FOR Loop --- name1
In FOR Loop --- name2
In FOR Loop --- name3Refer this link -- http://docs.oracle.com/cd/E11882_01/appdev.112/e17126/tuning.htm#CIHGGBGF
Edited by: ranit B on Dec 26, 2012 2:29 PM
-- code modified
Edited by: ranit B on Dec 26, 2012 2:45 PM
-- code 'again' updated -- FOR LOOP added
Similar Messages
-
Value select from nested table
CREATE TYPE test AS OBJECT (
test1 varchar2(10),
test2 varchar2(10));
create or replace type test2 as table of test;
two record are there within object type.then how i will select value from nested table.How many times are you going to ask this question before you either look at the response I have given to Re: how i will display type like (nestedtable or varrays or pl/sql table).?
You have posted often enough to this forum to know the ettiquette by now.
Regards, APC -
UPDATING A TABLE WITH SAME INFO FROM ANOTHER TABLE ON THE SAME DB
0down votefavorite
I am trying to update a table with info from another table on the same db with same table name. I just want the info to be the same , no primary key or constraint involve just a straight replacement of records and I keep getting errors WITH THE TABLE not
being recignize. below is my query:
UPDATE
VNDFIL
SET EOBTYP
= VNDFIL.EOBTYP,
EDI_X12_835_VERSION = VNDFIL.EDI_X12_835_VERSION
FROM
AGERECOVERY
WHERE
VNDFIL.EOBTYP
= VNDFIL.EOBTYP
AND
VNDFIL
.EDI_X12_835_VERSION
= VNDFIL.EDI_X12_835_VERSIONHi rotary,
If those two same named tables are in the same database then they have to be in different schemas. If you mean they are in the same server instance, then they may be in different databases, besides the "table not being recognized" error,
anyway you should use the fully qualified table names, that is database.Schema.Table(If across instances, ServerName should be prefixed) to avoid the table unrecognized error.
Using Identifiers As Object Names
With the fully qualified names, your update statement can be like below.
UPDATE
db1.schema1.VNDFIL
SET EOBTYP = srcTbl.EOBTYP, EDI_X12_835_VERSION = srcTbl.EDI_X12_835_VERSION
FROM
db1.schema2.VNDFIL srcTbl
WHERE
db1.schema1.VNDFIL.EOBTYP = srcTbl.VNDFIL.EOBTYP AND
db1.schema1.VNDFIL.EDI_X12_835_VERSION = srcTbl.VNDFIL.EDI_X12_835_VERSION
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support -
Retrieve data from nested tables
Hi All,
I have big trouble to retrieve data from nested tables..
From java code developer are passing struct data type to Oracle procedure.. So equal data type in oracle has been created as created as object
CREATE OR REPLACE TYPE TXNDATA AS OBJECT
TRAN_ID NUMBER ,
EVENT_ID NUMBER ,
EVENT_CD VARCHAR2(10 BYTE))and create a procedure which has a IN parameter as TXNDATA
now i need to retrieve the column data's through SELECT clause such as
TYPE Proc_txn IS TABLE OF TXNJOURNALDATA;
EVENT_JOURNAL_SEQ Proc_txn;
select * from table(cast(EVENT_JOURNAL_SEQ));but above SQL will give all column data's but i need to retrieve only 2 column values such as
select EVENT_ID , EVENT_CD from table(cast(EVENT_JOURNAL_SEQ))how can i achieve the above result set?
Thanks & Regards
Sami.use a table alias in your query
SQL> set serveroutput on
SQL> create TYPE TXNDATA AS OBJECT
2 (
3 TRAN_ID NUMBER ,
4 EVENT_ID NUMBER ,
5 EVENT_CD VARCHAR2(10 BYTE));
6 /
Type created.
SQL>
SQL> create type txnjournaldata
2 as table of txndata;
3 /
Type created.
SQL>
SQL> declare
2 txn txnjournaldata := txnjournaldata (
3 txndata(10, 20, 'One')
4 ,txndata(10, 20, 'Two')
5 );
6 begin
7 for rec in (select tx.event_id
8 , tx.event_cd
9 from table (txn) tx
10 )
11 loop
12 dbms_output.put_line (rec.event_id||' - '||rec.event_cd);
13 end loop;
14 end;
15 /
20 - One
20 - Two
PL/SQL procedure successfully completed.Edited by: Alex Nuijten on Oct 24, 2011 12:24 PM -
How to pull multiple lines of info from a table for a Specific Company/Address
What I would like to do is have one Table that I enter all my information on in Numbers for incoming rent like the one below. Since I have 8 spaces to rent I will have up to 96 plus rows of information to look at. But I would like to have Numbers then on separate pages is have the individual Companies have their own rent break down on a table with the Date Recieved and the amount they payed. From there on their separate page I can have the Late Charges come into play or whatever I choose.
Date
Company
Address
Rent Recieved
Jan 1, 2011
X
430
$1,100.00
Jan 3, 2011
Y
440
$1,200.00
Jan 5, 2011
Z
450
$1,300.00
Feb 1, 2011
Y
440
$1,200.00
Feb 3, 2011
X
430
$1,100.00
Feb 8, 2011
Z
450
$1,300.00
Mar 1, 2011
Z
450
$1,300.00
Mar 2, 2011
X
430
$1,100.00
Mar 5, 2011
Y
440
$1,200.00
The following table would be on the separate page with the formula (I do not know how to write) grabbing the info from the above table.
Company X Rent Recieved
Date
Rent Recieved
From the formula that one of you gracious smart people provide I could create a table for each of the Companies that rent from me on their own Tables on separate Tabs.
I know I could go to each individual Tab and write it in but I will be primarily working on my iPad and this would make it easier. I can also utilize the fresh Tables to do other calculations.I got a soluce with no swap.
I created a new column (E)
In E2, the formula is :
=B&IF(ISBLANK(A),"",MONTH(A))
Apply Fill Down
In table of each company, I inserted a 2nd header row so that I may store the name of the company in A1.
In A3, the formula is :
=IFERROR(OFFSET(Tableau 1 :: $A$1,MATCH($A$1&ROW()-2,Tableau 1 :: $E,0)-1,0),"")
in B3, the formula is :
=IFERROR(OFFSET(Tableau 1 :: $D$1,MATCH($A$1&ROW()-2,Tableau 1 :: $E,0)-1,0),"")
Select A3:B3 then Fill Down.
That's all folks !
Yvan KOENIG (VALLAURIS, France) jeudi 19 mai 2011 17:18:32
Please :
Search for questions similar to your own before submitting them to the community
To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer ! -
Select from nested table in a nested table security problem
please help
running Oracle 9.2.0.3.0 on RH AS 2.1
I can select the inner most nested table as the creator, but can't use the same select statement as USER2.
ORA-00942: table or view does not exist
-- begin make of objects and tables
create or replace type mydata_t as object ( x float, y float);
create or replace type mydata_tab_t as table of mydata_t;
create or replace type mid_t as object (
graphname varchar2(12),
datapoints mydata_tab_t );
create or replace type mid_tab_t as table of mid_t;
create or replace type top_t as object (
someinfo int,
more_mid mid_tab_t );
create table xyz (
xyzPK int,
mainstuff top_t )
nested table mainstuff.more_mid store as mid_nt_tab
(nested table datapoints store as mydata_nt_tab)
-- grants
grant all on mydata_t to user2;
grant all on mydata_tab_t to user2;
grant all on mid_t to user2;
grant all on mid_tab_t to user2;
grant all on top_t to user2;
grant all on xyz to user2;
-- insert
insert into xyz values (1, top_t(22,mid_tab_t(mid_t('line1',mydata_tab_t(
mydata_t(0,0),
mydata_t(15,15),
mydata_t(30,30))))));
commit;
-- select fails as user2
select * from table(select Y.datapoints as DP_TAB
from table(select X.mainstuff.more_mid as MORE_TAB
from scott.xyz X
where X.xyzPK=1) Y
where Y.graphname='line1') Z;
-- select works as user2, but i need individual lines
select Y.datapoints as DP_TAB
from table(select X.mainstuff.more_mid as MORE_TAB
from scott.xyz X
where X.xyzPK=1) Y
where Y.graphname='line1';Thank you for your reply.
I have tried
select value(t) from table t;
but it is still not working. I got almost the same answer as before.
Anyway thank you very much again.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by MARCELO OCHOA ([email protected]):
Originally posted by meimei wu ([email protected]):
[b]I created a nested object-relational table using REF type in oracle8i. when I tried to select * from the table, I got lots of number as the ref type values, but actually, the value in ref type should be of type varchar2 and number. The number I got looked like following code:
JARTICLE_REF_TYPE(000022020876108427C2FE0D00E0340800208FD71F76103B99B12009C0E0340800208FD71F,
Does anyone know how I can get the actual value that I inserted into the nested table?
your help is appreciated.<HR></BLOCKQUOTE>
Try this:
select value(t) from table t;
Best regards, Marcelo.
null -
Hi,
I create following types and table:
CREATE OR REPLACE TYPE obj_query AS OBJECT
(emp_id NUMBER(6)
,emp_first VARCHAR2(20)
,emp_last VARCHAR2(25));
CREATE OR REPLACE TYPE tab_query AS TABLE OF obj_query;
CREATE TABLE queryEmp
(id_row NUMBER
,beginTrans VARCHAR2(15)
,queryA VARCHAR2(100)
,resultEmp tab_query)
NESTED TABLE resultEmp
STORE AS nested_queryEmp;
I would like the output of the table queryEmp like this:
id_row beginTrans queryA emp_id emp_first emp_last
1 15:00 Select1 100 Joe King
101 John Queen
2 15:10 Select2 100 Leo King
101 Mett Queen
But Can I get this result with only SQL SELECT statement from this table?
I don't want to use PL/SQL, only SELECT in SQL*Plus.
Thank you
I'm sorry but output looks so bad.
So, I want to get the one row of id_row, beginTrans, queryA and all rows of nested table dmlStats to this "main" row and so on.
But not in PL/SQL
I hope, you understand me.
Thanks
Edited by: user9357436 on 2.11.2011 5:18
Edited by: user9357436 on 2.11.2011 5:25Arvind Ayengar wrote:
Can you please explain things in details, and just ensure you are in the correct forum.Is this reply directed at me or the OP? -
Deletin of rows from nested table(urgent)
hi
gurus
i have a table x having of two nested tables
1)table1 and 2) table 2
how to delete the perticular rows from the table2
if any body having with example that is more helpfull to me
pls help me in this issuehttp://asktom.oracle.com/pls/ask/f?p=4950:8:4908238426441699577::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:2010064718579,
-
Union all-distinct and remove duplicates from nested table?
Hi all,
I need a select that will bulk collect some data in my nested table.
I have two tables from which I need to select all the accounts only once.(remove duplicates).
Tried to search on the forum...but no luck.
I have a table with one column:
create table a1(account_no number);
and a second table with 3 columns.
create table a2 (account_no number, name number, desc varchar2 (100));
I have a nested table like:
table of a2%rowtype;
Can I select from this two table in one select and put in my nested table just one row per account?
if a I have in a 2a row like :
1 'test' 'test2'
2 aaaa aa
and in a1 a row like:
1
I want to put in my nested table just (1, null,null and 2,aaaa, aa)) or (1,test,test2 and 2,aaaa, aa). it does no matter what row from those two I insert.
Second question:
If I use:
BANNER
Oracle9i Release 9.2.0.5.0 - Production
PL/SQL Release 9.2.0.5.0 - Production
CORE 9.2.0.6.0 Production
TNS for 32-bit Windows: Version 9.2.0.5.0 - Production
NLSRTL Version 9.2.0.5.0 - Production
SQL>
what is the best solution to remove duplicates from a neste table like mine?
I thought that I can build another nested table and loop in my first nt and for each row I check in there was the same account in previous lines.
it will be like:
for i in 1....nt_first.count loop
for j in 1..i loop
--check if my line was in previous lines. if it was...do not move it in my second collection
end loop;it is this best option in oracle 9i?I have a table with one column:
create table a1(account_no number);
and a second table with 3 columns.
create table a2 (account_no number, name number, desc varchar2 (100));
all I need are the accounts. the rest ar extra data
that I can ignore in this step. But if it is
available, it is ok to use it.
using one select in this case is is much better that
trying to remove duplicates parsing some nested table
with FOR many times?
Thankshi,
try to use union. Union automatically removes duplicates between two or more tables.
with t1 AS
(select '3300000' account_no FROM DUAL UNION
select '6500000' account_no FROM DUAL union
select '6500000' account_no FROM DUAL union
select '6500000' account_no FROM DUAL union
select '6500000' account_no FROM DUAL
select * from t1ACCOUNT_NO
3300000
6500000 -
Merge possible from nested table?
I recently have started using the merge command for some of our standard 'upsert' procedures. The old design for inserts was coming from a Java web service that would send over a flat file, which in turn the Java would call an insert procedure n times while in a loop, and on each call the procedure would perform a single insert.
As you are probably already shaking your head, I realize this makes way too many database calls to be scalable and is poor design. So I now have modified the procedure to take a nested table as the input and I loop through the nested table and do all the inserts in a single procedure call. I now want to take advantage of bulk binding. I know there is the FORALL command, but I figured there was a way to do this with MERGE since the procedure does an update if a match is found instead. I didn't know if there is any syntax to do this as the oracle docs state the USING clause can be a table, view or subquery.
I am using Oracle 10gR2 and SQL Developer 3.x. This was my attempt:
CREATE TABLE merge_table
t_id NUMBER(9,0),
t_desc VARCHAR2(100)
CREATE OR REPLACE TYPE merge_type IS OBJECT
type_id NUMBER(9,0),
type_desc VARCHAR2(100)
CREATE OR REPLACE TYPE merge_list IS TABLE OF merge_type;
CREATE OR REPLACE PROCEDURE my_merge_proc(p_records IN merge_list)
AS
BEGIN
MERGE INTO merge_table MT
USING
SELECT
p_records.type_id,
p_records.type_desc
FROM DUAL
) D
ON
MT.t_id = p_records.type_id
WHEN MATCHED THEN UPDATE
SET
t_id = p_records.type_id,
t_desc = p_records.type_desc
WHEN NOT MATCHED THEN INSERT
t_id,
t_desc
VALUES
p_records.type_id,
p_records.type_desc
END;
show error
CLEAR SCREEN
SET SERVEROUTPUT ON
-- test script to execute procedure
DECLARE
l_list merge_list := merge_list();
l_size NUMBER(9,0) := 5;
BEGIN
l_list.EXTEND(l_size);
FOR i IN 1 .. l_size
LOOP
l_list(i) := merge_type(i,'desc ' || TO_CHAR(i));
END LOOP;
my_merge_proc(p_records => l_list);
END;
PROCEDURE my_merge_proc compiled
Warning: execution completed with warning
10/23 PLS-00302: component 'TYPE_DESC' must be declared
10/13 PL/SQL: ORA-00904: "P_RECORDS"."TYPE_DESC": invalid identifier
5/5 PL/SQL: SQL Statement ignoredI know the syntax isn't correct. How do I fix this or is it even possible to do what I am trying to do?Ironically, after thinking about this for another 5 minutes the answer finally came to me after I had given up hope:
CREATE OR REPLACE PROCEDURE my_merge_proc(p_records IN merge_list)
AS
BEGIN
MERGE INTO merge_table MT
USING
SELECT
type_id,
type_desc
FROM TABLE(p_records) -- change here
) R
ON
MT.t_id = R.type_id
WHEN MATCHED THEN UPDATE
SET
--MT.t_id = R.type_id, -- cannot update the same column from on clause
MT.t_desc = R.type_desc
WHEN NOT MATCHED THEN INSERT
MT.t_id,
MT.t_desc
VALUES
R.type_id,
R.type_desc
END;
show error
PROCEDURE my_merge_proc compiled
No Errors.
-- I run my anonymous script block from above
anonymous block completed
select * from merge_table;
T_ID T_DESC
1 desc 1
2 desc 2
3 desc 3
4 desc 4
5 desc 5 -
How can I get ALL the user info from WWW_FLOW_FND_USER -table?
Hi.
I use HTML DB authentication and therefore all my user information is stored in HTML DB tables. I can use :APP_USER to get USER_NAME, but in my application I need to have also USER_ID, FIRST_NAME, LAST_NAME and EMAIL_ADDRESS fields from database. I don't want to change any database/schema security level so I cannot read directly from WWW_FLOW_FND_USER -table when I am inside in SCOTT -schema/sec.level.
How to read all the information?Thank you for your help, but I cannot find any information about backage wwv_flow_user_api on OTN or in HTML DB documentation.
Where to start? -
Taking more time for retreving data from nested table
Hi
we have two databases db1 and db2,in database db2 we have number of nested tables were there.
Now the problem is we had link between two databases,whenever u firing the any query in db1 internally it's going to acces nested tables in db2.
For feching records it's going to take much more time even records are less in table . what would be the reason.
plz help me daliy we are facing the problem regarding the samePlease avoid duplicate thread :
quaries taking more time
Nicolas.
+< mod. action : thread locked>+ -
Retrieve and display info from 3 tables
Been struggling with this for some days now. Setting up a calendar with football fixtures. For some reason, the team names do not appear in the table and this is really killing me. I thought I knew something about sql and php, guess not.
So for building up this page, I use 3 tables, Season, Teams & Calendar containing a.o. these columns. The first table, season, has only 1 record/row, being the season that's up, in this case 2010-2011:
Season
id (primary key - AI)
current
Teams
id (primary key - AI)
season
leagueid
teamid (unique value)
teamname
Calendar
id (primary key - AI)
season
leagueid
hometeamid
awayteamid
So, what the query should look like is, based on that 1 record from the table season, it has to select all games from the table calendar, selecting all the columns as displayed above. Now that's the easiest part, the hardest part is, replacing the hometeamid AND awayteamid by their names from the teams table. The teamid you see in the table teams is also used in the table calender. Below some basic input from the tables in question, to get a better feel of it:
Season
1
2010-2011
Teams
ID
Season
League ID
Team ID
Team Name
1
2010-2011
u12
1245-u12aa
Team XYZ
2
2010-2011
u8a
9521-u8a
Team ABC
3
2010-2011
u12
1245-u12a
Team HFH
Calendar
ID
Season
League ID
Hometeam ID
Awayteam ID
1
2010-2011
u12
1245-u12aa
5874-u12a
2
2010-2011
u12
9521-u12ab
7436-u12abSo far you have 4 tables, so the links between the 4 tables is:
1)id from season table(parent) is linked to seasonid from teams table(child)
2)id from season table(parent) is linked to seasonid from calendar table(child)
3)id from league table(parent) is linked to leagueid from teams table(child)
So the joins between them are:
JOIN1: season.id=teams.seasonid
JOIN2: season.id=calendar.seasonid
JOIN3: league.id=teams.leagueid
To extract from multiple tables, SQL query would be as follows:(criteria 1 is optional)
SELECT * FROM teams,season,league,calendar
WHERE [CRITERIA 1] AND JOIN1 AND JOIN2 AND JOIN3
To create relational tables, change all the tables ENGINE=INNODB
then
ALTER TABLE foreign table name ADD FOREIGN KEY(' insert foreign key') REFERENCES(' insert database.primary table.primary key ')
ON DELETE CASCADE ON UPDATE CASCADE -
Newbie question - trying to apply info from a table to a cell
I'm a trucker who has purchased a MBP and want to use a spreadsheet to calculate cost for fuel. I am familiar with spreadsheets, but not that in depth. I want to be able to apply state taxes for fuel cost, but not sure how to apply it using a table. I want to use a cell to type in the state abbreviation and have the cell apply the state sales tax to my spreadsheet from a table with all the states and sale taxes. Here the table I have set up in my spreadsheet.
STATE RATE
AL $0.19
AK $0.08
AZ $0.26
AR $0.225
CA $0.367
CO $0.205
CT $0.26
DE $0.22
DC $0.00
FL $0.3057
GA $0.141
HI $0.00
ID $0.25
IL $0.367
IN $0.27
IA $0.225
KS $0.26
KY $0.222
LA $0.20
ME $0.279
MD $0.2425
MA $0.21
MI $0.28
MN $0.20
MS $0.18
MO $0.17
MT $0.2775
NE $0.27
NV $0.27
NH $0.18
NJ $0.175
NM $0.21
NY $0.3685
NC $0.299
ND $0.23
OH $0.28
OK $0.13
OR $0.24
PA $0.381
RI $0.30
SC $0.16
SD $0.22
TN $0.17
TX $0.20
UT $0.25
VT $0.26
VA $0.195
WA $0.34
WV $0.315
WI $0.329
WY $0.14
Any help would be appreciated a great deal.
"El Capitone"
P.S. if you need to see the actual spreadsheet, I can send it to you by email. I tried to attach it to this message, but was unable to do so.El Capitone,
I'm assuming you want to find the total amount of state taxes paid to each individual state, but I'm not sure what these rates mean or how they are to be applied. Actually, their application may vary from state to state. However, two possiblities are shown here and if this is not what you want you'll get back to us.
1. If the rates mean $ per gallon then tax paid is is shown in column D below and the formula is:
=IF(ISBLANK(Gals),"",Tax Rate*Gals)
2. If the rate means a percent of the pump price after all other taxes and charges are added in, the result appears in column F:
=IF(ISBLANK(Tot Cost),"",Tot Cost-Tot Cost/(1+Tax Rate))
As I say, I have the feeling this problem may be more complex.
pw -
Return Minimum from Nested Table and Include
Hello -
Complete noob to the SQL world but trying :)
I know I can do this in multiple tables, but trying to do it all in one pull...I have data that is counting the number of employees by ID number across several years....(2011 - 2014) - I am using a nested Query to get my origin info, and trying to replicate
the minimum initial year across each row in the return......
I am returning minimum per year found, when what I want is minimum across all years for each account
My data looks as such :
Initial
YR
candidate_account_num
segment
sector
subsector
NumEngage
2011
2011
000001987
MM
West
1
2012
2012
000001987
MM
West
6
2013
2013
000001987
MM
West
1
What I want it to show is :
Initial
YR
candidate_account_num
segment
sector
subsector
NumEngage
2011
2011
000001987
MM
West
1
2011
2012
000001987
MM
West
6
2011
2013
000001987
MM
West
1
2011 is the lowest year for that account num of the three instances....
Thanks so much for any insight....
Select
min
(A.YR)
as Initial
,A.YR
,A.candidate_account_num
,A.segment
,A.sector
,A.subsector
,A.NumEngage
From
(select
year(producing_date)
as YR
,candidate_account_num
,segment
,sector
,subsector
,count(soy_id_nr)
as NumEngage
from csinternalstaging.dbo.tmp_Producingsolutions
where producing_date
>='1/1/2011'
and segment not
in ('INTL')
group by
year(producing_date)
,candidate_account_num
,segment
,sector
,subsector
A
group
by
YR
,candidate_account_num
,segment
,sector
,subsector
,NumEngage
order by
candidate_account_num,
yrselect
Min(year(producing_date)) OVER(PARTITION
BYcandidate_account_num,
segment, sector,
subsector) as
Initial
,year(producing_date)asYR
,candidate_account_num
,segment
,sector
,subsector
,count(soy_id_nr)
as NumEngage
from csinternalstaging.dbo.tmp_Producingsolutions
where producing_date
>='1/1/2011'
and segment not
in ('INTL')
group by
year(producing_date)
,candidate_account_num
,segment
,sector
,subsector
Maybe you are looking for
-
How can I get a paypal text box to show up in Muse?
I'm using paypal for my shopping cart. There was no problem adding the paypal generated HTML to the pages - everything works as it should, except for the text boxes where customers are supposed to input some specific information. The information can
-
How do I change the text of a specific MESSAGE field for a specific Alert
I want to change the text for the "Message" field (10.2.0.5 OEMGC) for the "Blocking Session Count" alert that shows up in Notifications. Does anyone know where the text is stored? I do not find it in Preferences>Rules in the Console nor in any obvio
-
The Sims 2 UB Rev E..FINALLY!
YAY!!! I just checked the ASPYR website and they have come out with the Universal Binary Patch Rev E which according to ASPYR "Fixes a bug on Intel Macs where all offspring of a couple had identical facial features." The Rev D drove me crazy with the
-
hi, this is probably a stupid question but how can I simply generate java classes based on an XSD using JAXB. I've been browsing some tutorials but this part is never really explained except for using some script called xjc. This script however seems
-
Call variant from ABAP program
Hi all, The users have created a variant that they use when they run their report. When they select the variant it works fine, but they want the program to run the variant for them. Can anyone give me some ideas as to where I can go to see some sam