SELECT max query
HelloI'm trying to select the record from the scenario below.
Oracle Database 10 g Enterprise Edition release 10.2.0.3.0 - 64bi
CREATE TABLE T4
(
MID NUMBER,
PID NUMBER,
SID VARCHAR2(32 BYTE),
SUPPLIER NUMBER,
UPDT TIMESTAMP(6),
EDT DATE
)
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT, EDT)
Values
(44333949, 136349891, '36219891030F', 4447, TO_TIMESTAMP('1/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'), TO_DATE('01/05/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT, EDT)
Values
(47016634, 670608153, '36219891030F', 4447, TO_TIMESTAMP('1/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'), TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT, EDT)
Values
(44333951, 136349891, '36219891030F', 4447, TO_TIMESTAMP('1/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'), TO_DATE('01/04/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT)
Values
(47123075, 670095796, '46919640411M', 4447, TO_TIMESTAMP('4/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT)
Values
(44258745, 137364687, '46919640411M', 4447, TO_TIMESTAMP('1/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT, EDT)
Values
(47123075, 670095796, '46919640412M', 4447, TO_TIMESTAMP('1/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'), TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT, EDT)
Values
(21475309, 28688687, '90820050905M', 4447, TO_TIMESTAMP('4/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'), TO_DATE('01/04/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT, EDT)
Values
(45059090, 163943597, '90820050905M', 4447, TO_TIMESTAMP('1/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'), TO_DATE('01/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into T4
(MID, PID, SID, SUPPLIER, UPDT)
Values
(42383558, 97371230, '90820050905M', 4447, TO_TIMESTAMP('5/1/2010 12:00:00.000000 AM','fmMMfm/fmDDfm/YYYY fmHH12fm:MI:SS.FF AM'));
COMMIT;
Scenario
if all Edt is populated pick the latest based on edt
select * from t4 where sid='46919640412M' and SUPPLIER=4447
MID PID SID SUPPLIER UPDT EDT PICK
47123075 670095796 46919640412M 4447 1/1/2010 1/1/2010 1
if all edt is null pick the latest based on updt
select * from t4 where sid='46919640411M' and SUPPLIER=4447
MID PID SID SUPPLIER UPDT EDT PICK
44258745 137364687 46919640411M 4447 1/1/2010
47123075 670095796 46919640411M 4447 4/1/2010 1
if edt is populated pick the one based on latest updt with out considering the edt not null
select * from t4 where sid='90820050905M' and SUPPLIER=4447
MID PID SID SUPPLIER UPDT EDT PICK
45059090 163943597 90820050905M 4447 1/1/2010 1/1/2010
42383558 97371230 90820050905M 4447 5/1/2010 1
21475309 28688687 90820050905M 4447 4/1/2010 1/4/2010
if all edt is found pic the latest based on edt.
select * from t4 where sid='36219891030F' and SUPPLIER=4447
MID PID SID SUPPLIER UPDT EDT PICK
47016634 670608153 36219891030F 4447 1/1/2010 1/1/2010
44333949 136349891 36219891030F 4447 1/1/2010 1/5/2010 1
44333951 136349891 36219891030F 4447 1/1/2010 1/4/2010
I tried like this its not satisfying all the scenarios.SOME mediums,
nest,
SID,
provider,
Shift,
EDT,
ROW_NUMBER)
MORE THAN
(
ORDER BY CASE WHEN edt IS NOT NULL THEN ELSE END DESC edt SYSDATE
)
Pick
T4
WHERE sid = '36219891030F' AND provider = 4447
Thank you
Alen
With the help of analytical functions;
select sid,
supplier,
updt,
edt,
case
when (cnt_edt = cnt_all and edt = max_edt)
or (cnt_edt != cnt_all and updt = max_updt) then
1
end pick1
from (select t4.*,
count(edt) over(partition by sid, supplier) cnt_edt,
count(*) over(partition by sid, supplier) cnt_all,
max(updt) over(partition by sid) max_updt,
max(edt) over(partition by sid) max_edt
from t4)
order by 1,2,3,4;
SID SUPPLIER UPDT EDT PICK1
------------- ---------- ------------------------- ----------- -----
36219891030F 4447 10-01-01 00:00:00,000000 01/01/2010
36219891030F 4447 10-01-01 00:00:00,000000 04/01/2010
36219891030F 4447 10-01-01 00:00:00,000000 05/01/2010 1
46919640411M 4447 10-01-01 00:00:00,000000
46919640411M 4447 10-04-01 00:00:00,000000 1
46919640412M 4447 10-01-01 00:00:00,000000 01/01/2010 1
90820050905M 4447 10-01-01 00:00:00,000000 01/01/2010
90820050905M 4447 10-04-01 00:00:00,000000 04/01/2010
90820050905M 4447 10-05-01 00:00:00,000000 1
Edited by: MScallion may 7, 2010 14:24 - replaced braces with! =
Tags: Database
Similar Questions
-
Select Max (date) multiple records
I'm having a problem getting the last value for several gauges. Here's my query:
SELECT parameter_id,
TS_ID,
value,
Location_id,
Date_Time
Of
MyTable
JOIN IN-HOUSE
mytable2
WE
TS_ID = ts_id
WHERE
TS_ID LIKE '% - rev.
unit_id = ("pi")
the value IS NOT NULL
Location_id as "xxxx".
Date_Time =
(SELECT Max (date_time)
My TABLE
GROUP BY parameter_id)
;
Hello
A scalar subquery, such as the expression to the right of the sign =
Date_Time = (SELECT...)
must produce (at most) only 1 row. If the subquery produces 2 or more lines, it will trigger an error.
Given that you are using "GROUP BY parameter_id" in the subquery, it will produce a separate line of output for each distinct value of parameter_id. You can use a correlated subquery at that time, that only looks like a parameter_id, or you can use a subquery IN, like this:
WHERE (parameter_id, Date_Time) IN
(
SELECT parameter_id
MAX (date_time)
FROM MyTable
GROUP BY parameter_id
)
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
Hello
I executed the query below
SELECT CUREPRESS, PRODUCTIONCODE, ENDDATE YYYYMMDD.
CASE
WHEN annex 1 > 0 AND SCHEDULE2 > 0 AND THEN schedule3 > 0 AND ROUND(22+SCHEDULE3/CURECAPACITY*24,0) > 24
Round (22 +(SCHEDULE3/CURECAPACITY*24) - 24, 0)-(DATE of the INCREASE OF 1)
WHEN annex 1 = 0 AND SCHEDULE2 = 0 AND schedule3 > 0 AND ROUND(22+SCHEDULE3/CURECAPACITY*24,0) < = 24 THEN
Round(22+SCHEDULE3/CURECAPACITY*24,0)
WHEN annex 1 > 0 AND SCHEDULE2 > 0 AND schedule3 = 0 THEN
Round(14+SCHEDULE2/CURECAPACITY*24,0)
WHEN annex 1 > 0 AND SCHEDULE2 = 0 AND = 0 THEN schedule3
ROUND (6 +(SCHEDULE1/CURECAPACITY*24), 0)
END ENDDATE1
CEN
SELECT PRODUCTIONCODE, curepress, YYYYMMDD
OF ORGCURESCHEDULEDAY HAS
WHERE YYYYMMDD = (SELECT MAX (YYYYMMDD)
OF ORGCURESCHEDULEDAY B
WHERE A.PRODUCTIONCODE = B.PRODUCTIONCODE
AND A.CUREPRESS = B.CUREPRESS)
) PRODUCTIONCODE, CUREPRESS, YYYYMMDD GROUP
ORDER OF CUREPRESS, PRODUCTIONCODE
But... I get the error message like
ORA-00904: "CURECAPACITY": invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
Error on line: column 103: 40
Pls help me... !!SELECT CUREPRESS, PRODUCTIONCODE, STARTDATE, TO_DATE(TO_CHAR(STARTDATE,'YYYYMMDD') || TO_CHAR(STARTDATE1,'HH24')||':00','YYYYMMDD HH24:MI') STARTDATE1 FROM (SELECT CUREPRESS, PRODUCTIONCODE, YYYYMMDD STARTDATE, CASE WHEN SCHEDULE1 = 0 AND SCHEDULE2 = 0 AND SCHEDULE3 >0 AND ROUND(30 -SCHEDULE3/CURECAPACITY*24,0)>24 THEN ROUND(30-(SCHEDULE3/CURECAPACITY*24),0)-24 WHEN SCHEDULE1 = 0 AND SCHEDULE2 = 0 AND SCHEDULE3 >0 AND ROUND(30 -SCHEDULE3/CURECAPACITY*24,0)<=24 THEN ROUND(30-SCHEDULE3/CURECAPACITY*24,0) WHEN SCHEDULE1 = 0 AND SCHEDULE2 >0 AND SCHEDULE3 >0 THEN ROUND(22-SCHEDULE2/CURECAPACITY*24,0) WHEN SCHEDULE1 > 0 AND SCHEDULE2 >0 AND SCHEDULE3 >0 THEN ROUND(14-SCHEDULE1/CURECAPACITY*24,0) END STARTDATE1 FROM (SELECT curepress, PRODUCTIONCODE, YYYYMMDD, schedule1, schedule2, schedule3, curecapacity FROM ORGCURESCHEDULEDAY A WHERE YYYYMMDD = (SELECT MIN(YYYYMMDD) FROM ORGCURESCHEDULEDAY B WHERE A.PRODUCTIONCODE=B.PRODUCTIONCODE AND A.CUREPRESS =B.CUREPRESS ) ) GROUP BY PRODUCTIONCODE, CUREPRESS, YYYYMMDD, SCHEDULE1, SCHEDULE2, SCHEDULE3, CURECAPACITY) ORDER BY CUREPRESS, PRODUCTIONCODE
Try please, (not tested)
-
With the help of SELECT MAX (Substr (in a subquery to return specific lines
Oracle v10
Here is an example of a query and the output
I try to return only the last line of data, in this case the line 2005.SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 WHERE SAMPLEID = 'IA 0005 0166'; 86907 IA 0005 0166 IA 0005 R2004:001160 2004 98158 IA 0005 0166 IA 0005 R2005:000956 2005
I tried
But it returns no results. According to me, only missing me something simple.SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 WHERE SAMPLEID = 'IA 0005 0166' AND REQUISITION IN (SELECT MAX(SUBSTR(REQUISITION,2,4)) FROM SEARCH PL2 WHERE SUBSTR(PL2.REQUISITION,2,4) = SUBSTR(PL1.REQUISITION,2,4));
TIAYou probably meant it?
SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 WHERE SAMPLEID = 'IA 0005 0166' AND SUBSTR(REQUISITION,2,4) = ( SELECT MAX(SUBSTR(PL2.REQUISITION,2,4)) FROM SEARCH PL2 WHERE PL2.SAMPLE_ID = PL1.SAMPLE_ID );
that could also be achieved with a single table access:
SELECT id, sampleid, compoundname, requisition, sub_req FROM ( SELECT id, sampleid, compoundname, requisition, substr(requisition,2,4) sub_req, row_number() over(order by substr(requisition,2,4) desc) rn FROM search PL1 WHERE sampleid = 'IA 0005 0166' ) WHERE rn = 1 ;
-
Select max in a specific range only?
Hello experts and pros of sql!
I guess that I need your help on a problem I've been struggling with for hours now.
I have the following query, which, in the final version will be written in the pl/sql code:
My problem is that I want to select MAX (M.LNG_ARBEITSSCHRITT) while the max value is supposed to be limited to a specific range.SELECT CNT_GEBIET, CNT_GEBIET DISPLAY, CNT_GEBIET BUTTON, STR_NAME, decode(STR_ART_GEBIETE,'Vogelschutz','SPA','FFH','FFH','FFH und Vogelschutz','FFH & SPA') STR_ART_GEBIETE, STR_REG_KART_TEAMS, STR_BESCHREIBUNG, BOOL_ANZEIGEN, STR_FEDERFUEHRENDE, K.INT_VERFAHREN, STR_VERFAHREN, D.ST_BIOGEO, D.STR_GEBIET, E.STR_BIOGEO, E.INT_BIOGEO, case when to_char(min(L.DATE_GP_RT_END), 'YYYY') < to_char(sysdate, 'YYYY') then 'red' else 'green' end as mxcolour, case when to_char(min(L.DATE_R_AT_END), 'YYYY') <= to_char(sysdate, 'YYYY') then 'green' when to_char(min(L.DATE_R_V_END), 'YYYY') > to_char(min(L.DATE_GP_V_END), 'YYYY') then 'red' else 'black' end as mxcolour_r_date, to_char(min(L.DATE_GP_AT_START), 'YYYY') DATE_GP_AT_START, to_char(min(L.DATE_R_AT_END), 'YYYY') DATE_R_AT_END, to_char(min(L.DATE_GP_V_START), 'YYYY') DATE_GP_V_START, to_char(min(L.DATE_R_V_END), 'YYYY') DATE_R_V_END, to_char(min(L.DATE_GP_RT_START), 'YYYY') DATE_GP_RT_START, to_char(min(L.DATE_R_RT_END), 'YYYY') DATE_R_RT_END, I.GEB, I.STR_REGBEZE, H.ALF, I.LNG_REG_KART_TEAMS, MAX(NVL(M.LNG_ARBEITSSCHRITT,21)) LNG_ARBEITSSCHRITT FROM VT_TBL_ARBEIT_ZU_GEBIET M RIGHT OUTER JOIN ( VT_TBL_GEBIET K INNER JOIN VT_TBL_ART_GEBIETE B ON B.CNT_ART_GEBIETE = K.INT_ART_GEBIET INNER JOIN VT_TBL_FEDERFUEHRENDE C ON C.CNT_FEDERFUEHRENDE = K.LNG_FEDER INNER JOIN VT_TBL_GEBIET_ZU_BIOGEO D ON D.STR_GEBIET = K.CNT_GEBIET INNER JOIN VT_TBL_BIOGEO E ON D.ST_BIOGEO = E.INT_BIOGEO INNER JOIN VT_TBL_VERFAHREN F ON F.CNT_VERFAHREN = K.INT_VERFAHREN INNER JOIN VT_TBL_REG_KART_TEAMS G ON G.CNT_REG_KART_TEAMS = K.INT_REG_KART_TEAMS INNER JOIN VT_TBL_GEBIET_ZU_ALF H ON H.GEBIET = K.CNT_GEBIET INNER JOIN TBL_REGBEZE I ON I.GEB = K.CNT_GEBIET AND I.LNG_REG_KART_TEAMS = G.CNT_REG_KART_TEAMS ) ON M.LNG_GEBIET = K.CNT_GEBIET LEFT OUTER JOIN TBL_ARBEITSSCHRITTE_NEU A ON M.LNG_ARBEITSSCHRITT = A.CNT_ARBEITSSCHRITT left outer join vt_tbl_arbeit_crit_date l on l.lng_gebiet = k.cnt_gebiet where k.cnt_gebiet not like '%Test%' and nvl(m.lng_arbeitsschritt,21) not in (1,4,13,23,28,31,45,54,60,66,73,78) and nvl(l.lng_arbeitsschritt,1) = 1 GROUP BY CNT_GEBIET, STR_NAME, STR_ART_GEBIETE, STR_REG_KART_TEAMS, LNG_REG_KART_TEAMS, H.ALF, STR_BESCHREIBUNG, BOOL_ANZEIGEN, STR_FEDERFUEHRENDE, D.ST_BIOGEO, D.STR_GEBIET, E.STR_BIOGEO, E.INT_BIOGEO, F.STR_VERFAHREN, K.INT_VERFAHREN, I.GEB, I.STR_REGBEZE, L.DATE_GP_AT_START, L.DATE_R_AT_END, L.DATE_GP_V_START, L.DATE_R_V_END, L.DATE_GP_RT_START, L.DATE_R_RT_END
Indeed, the 1,4,13,23,28,31,45,46,54,60,66,73,78 values should not take into account.
Can you please show me how to specify a range of values that can be used for the calculation of the max (m.lng_arbeitsschritt)?
I appreciate your help and your entry!
Thank you to have a look at this post!
Kind regards
SEBTry:
max(case when M.LNG_ARBEITSSCHRITT not in (1,4,13,23,28,31,45,46,54,60,66,73,78) then M.LNG_ARBEITSSCHRITT end)
-
Select max (length) - how to display the length of a group MAX
Hello
I have a table with the name of DVD and names of files on the DVD.
I would like to know how to change this query to get another column, MAX_LENGHT, the MAXIMUM length of the name of FILE to a DVD of return
This doesn't work request
DESIRED RESULTselect DVD, FILENAME, (SELECT max(length(FILENAME)) / 2 + 4 FROM TABLE) AS MAX_LENGHT from TABLE
Thank youDVD FILENAME MAX LENGHT DVD1 Alina 8 DVD1 Aidan 8 DVD1 Aiden 8 DVD1 Akira 8 DVD1 Alex 8 DVD1 Alyssa 8 DVD1 Arianna 8 DVD1 Ashley 8 DVD1 Ava 8 DVD1 Benjamin8 DVD1 Bianca 8 DVD1 Blake 8 DVD1 Brandon 8 DVD1 Brayden 8 DVD1 Brayden 8 DVD1 Brianna 8 DVD1 Brielle 8 DVD1 Brooklyn8 DVD2 Dakota 11 DVD2 Dalia 11 DVD2 Daniel 11 DVD2 Dante 11 DVD2 David 11 DVD2 Diego 11 DVD2 Dingbang11 DVD2 Dominic 11 DVD2 Dylan 11 DVD2 Chase 11 DVD2 Chloe 11 DVD2 Christopher 11 DVD2 Claire 11 DVD2 Cole 11 DVD2 Connor 11
RoselineYou can use the analytic version of the function max:
SELECT DVD , FILENAME , MAX(LENGTH(FILENAME)) OVER (PARTITION BY DVD) AS MAX_LENGTH FROM TABLE
-
HELP! : SELECT &; MAX
I had a few difficulties to do a sql query.
Table 1: Master
2 columns: name, Contact_ID
Name1, contact_id_1
name 2, contact_id_2
name 3, contact_id_3
...
Table 2: details
2 columns: Version Contact_id, address,.
contact_id_1, address_a, 1
contact_id_1, address_b, 2
contact_id_2, address_c, 1
contact_id_2, address_d, 2
contact_id_2, address_e, 3
contact_id_3, address_f, 1
......
Question I have:
How can I make a query showing the list of names with the address with the latest version?
Result: I'm looking:
Name1, address_b
name 2, address_e
name 3, address_f
.......
--------------------------
Thank you very much for the help in advance!with master as ( select 'name1' as name, 'contact_id_1' as contact_id from dual union all select 'name2' as name, 'contact_id_2' as contact_id from dual union all select 'name3' as name, 'contact_id_3' as contact_id from dual ), detail as ( select 'contact_id_1' as contact_id, 'address_a' as address, 1 as version from dual union all select 'contact_id_1' as contact_id, 'address_b' as address, 2 as version from dual union all select 'contact_id_2' as contact_id, 'address_c' as address, 1 as version from dual union all select 'contact_id_2' as contact_id, 'address_d' as address, 2 as version from dual union all select 'contact_id_2' as contact_id, 'address_e' as address, 3 as version from dual union all select 'contact_id_3' as contact_id, 'address_f' as address, 1 as version from dual ) -- -- end of test data, query is below -- select m.name, d.address from master m, detail d where m.contact_id = d.contact_id and d.version = (select max(version) from detail d2 where d2.contact_id = d.contact_id) / NAME ADDRESS ----- --------- name1 address_b name2 address_e name3 address_f 3 rows selected
Published by: Cyn on December 17, 2009 16:39
-
Text ToolTip APEX of select list query
Hi all
Currently, I'm stuck with how to display the ToolTip text by using a selection list query. I tried to look for the solution but I got is: assigning help unique text value. I also passed by the example:
https://Apex.Oracle.com/pls/Apex/f?p=44321:410:
When I'm hovering above the value of column Loc Departments IR, , it displays the ToolTip text in a list. My requirement is almost the same. I will implement for the page element and the value of the list will be generate by query.
I use 5 APEX with Database 11g
Any help would be appreciated.
Concerning
Nabila
I solved this problem. I just want to share this, if anyone needs.
1 created dynamic action on loading of the page.
2. Choose the action ToolTip [plug-ins].
3. ToolTip content type: Code PL/SQL which is:
Start
Select: P260_FINANCIALINSTRUMENT
in l_help_text
Double;
HTP.p (replace (nvl (l_help_text, "no help is found.'"), ', ' '))
'));exception
while others then
HTP.p ('no help is found.');
end;
4. affected elements--> JQuery selector:
Label [for = P78_FINANCIALINSTRUMENT] Caddy-tip
Note:
I used the Tooltip Plugin which is mentioned in my original post.
78 is my page number created if the dynamics of the action when the page is loaded. And P78_FINANCIALINSTRUMENT matches the element for which the ToolTip will come as a selection list.
P260_FINANCIALINSTRUMENT is the element that contains the actual value of the selection list. I used the database query to get the value separated by,
Start
Select listagg (Orders, ',')
THE Group (Control Orders) Orders
in: P260_FINANCIALINSTRUMENT
of Orders;
end;
Thank you
-
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.
-
Select Max (date) between multiple tables
I need to retrieve a record from a Table in a set of similar tables with a common "date field". You can select the record where this "date field" value is greater between multiple tables.
Here, any help is appreciated. Thank you in advance.
FOR EXAMPLE
No. EMP is the primary key.
Again, each table can have multiple records for EMP n ° 1
TABLE1:
FIRST NAME
FAMILY NAME
THE EMP NO.BASE SALARY
DATE_FROM
TABLE 2
FIRST NAME
FAMILY NAME
THE EMP NO.SALARY GRADE
DATE_FROM
TABLE 3
FIRST NAME
FAMILY NAME
THE EMP NO.COMPENSATION
DATE_FROM
Hello
Said Knani, if you use the current design of the table, then here is a way to do what you want:
WITH union_data AS
(
SELECT MAX (base_salary) AS sal FROM table1 UNION ALL
SELECT MAX (grade_salary) table2 UNION ALL
SELECT MAX (compensation) FROM table3
)
SELECT MAX (sal) AS max_sal
Of union_data
;
-
Hello
I have a table named demo with two columns (name brands), as shown below
Name brands
A 80
B 100
C 96
I need a Select SQL query that returns the result as shown below
Name brands
A 276
B 276
C 276
Brands of column must contain the sum of all the brands of the table against each of the name of the table. (Not necessarily with the same columns as the demo table names) This result should not be stored in the table and I need it just for display purpose.
Published by: 944160 on May 30, 2013 05:28Try this
select name, sum(marks) over () marks from demo
-
Select the query with the level line list where the clause
Hi all
I am creating a tabular presentation based on a SQL query that has a list of selection based on a query with a where clause clause that refers to a column in the original SQL query.
The situation is, I have a table that stores the client_id, source_id, and build_id, lets call it client_source. I have a second table, build_source, containing source_id and build_id, one to many relations between the two (1 source_id could have build_id 1-7).
Using a tabular presentation, I want to select the correspondent build_id to use in client_source, but the selection list should contain only the build_id for this particular source_id of lines.
Here is an example of the SQL source of tabular presentation;
Select
s.ROWID,
s.CLIENT_ID,
s.SOURCE_ID,
APEX_ITEM. SELECT_LIST_FROM_QUERY (1, s.BUILD_ID,)
"Select display b.build_id, b.build_id return.
b build_source where b.source_id = s.SOURCE_ID ') lst
of s client_source
what I want to achieve, it's as source_id "BOLD" match fields. When the query is built this way, I get an error of "invalid identifier" Oracle on s.SOURCE_ID during execution.
Is there some special tags to be used to refer to the external column? I must be missing something because this looks like a pretty mundane problem.
I am running on 4.1.0.00.32, on an Oracle 10 g release 10.2.0.4.0 Server Express request.
I look forward to useful responses!
See you soon,.
Jason
Published by: 1005131 on May 9, 2013 19:02Your selection by query list receives a static SQL. That SQL can't "see" the value of your s.source_id.
But it would work like this:
where b.source_id = ' | s.SOURCE_ID)You would be the value for the SQL concatenation. It is not ideal, but it will work.
Jorge
-
Hello guys, small head scratcher here (probably just my mind head)
Summary of the issue: Updated between two tables, try to use the rank, will not work.
I took a few of the fields of interest here: -.
CREATE TABLE spell_tags ( Spell_ID varchar2(50) , service_line_spell varchar2(25) );
Samples: -.CREATE TABLE ranked_spells( spell_ID varchar2(10) , dominant_SSNDS varchar2(25) , service_line varchar2(25) , Rank varchar2(3) NOT NULL ) ;
Data looks like this: -.INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100002' ,'08' ,'SD08o' ,'213' ); INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100002' ,'08' ,'SD08s' ,'210' ); INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100003' ,'08' ,'SD22m' ,'416' ); INSERT INTO RANKED_SPELLS ("SPELL_ID" ,"DOMINANT_SSNDS" ,"SERVICE_LINE" ,"RANK" ) VALUES ('100003' ,'08' ,'SD23x' ,'207' ); INSERT INTO SPELL_TAGS ("SPELL_ID" , "SERVICE_LINE_SPELL" ) VALUES ('100002' ,'' ); INSERT INTO SPELL_TAGS ("SPELL_ID" , "SERVICE_LINE_SPELL" ) VALUES ('100003' ,'' );
Basically, I need to run and update the declaration (not plsql) to update the Spell_tags table service_line_spell field with the service_line of the ranked_spells table (lowest rank)Select * from spell_tags; SPELL_ID SERVICE_LINE_SPELL -------------------------------------------------- ------------------------- 100002 100003 2 rows selected. Select * from ranked_spells; SPELL_ID DOMINANT_SSNDS SERVICE_LINE RANK ---------- ------------------------- ------------------------- --- 100002 08 SD08o 213 100002 08 SD08s 210 100003 08 SD22m 416 100003 08 SD23x 207 4 rows selected.
Here are a few failed attempts, do not laugh ;)
This is the result, I need: -.update spell_tags set service_line_spell = (select max(service_line) from ranked_spells where spell_tags.spell_id = ranked_spells.spell_ID group by service_line, rank having rank = min(rank)) where spell_ID in (select distinct spell_ID from ranked_spells); ERROR at line 2: ORA-01427: single-row subquery returns more than one row update speccom.spell_tags set service_line_spell = (select b.service_line from ranked_spell b where spell_tags.spell_id = ranked_spells.spell_ID and ranked_spells.rank = min(ranked_spells.rank) group by service_line, rank) where exists (select spell_ID from ranked_spells where spell_ID in (select distinct spell_ID from ranked_spells); ERROR at line 4: ORA-00934: group function is not allowed here
Any ideas guys?Select * from spell_tags; SPELL_ID SERVICE_LINE_SPELL -------------------------------------------------- ------------------------- 100002 SD08s 100003 SD23x
Something like that?
update spell_tags set service_line_spell = (select max(service_line) keep (dense_rank last order by rank desc) from ranked_spells where spell_tags.spell_id = ranked_spells.spell_ID ) where spell_ID in (select distinct spell_ID from ranked_spells);
Published by: UW (Germany) on 16.08.2012 16:48 (changed min at the maximum, but it makes only a difference when there is same ranking values)
-
SELECT MAX (FILE_VERSION)
I put the following portion of the code in a WHERE clause:
.. .but for records where the FILE_VERSION is null or doesn't retrieve any record.AND PCMS_CHDOC_ACTION_DESC_2.FILE_VERSION IN (SELECT MAX(FILE_VERSION) FROM PCMS_CHDOC_ACTION_DESC PCMS_CHDOC_ACTION_DESC_4 WHERE PCMS_CHDOC_ACTION_DESC_4.CH_UID = PCMS_CHDOC_DATA_2.CH_UID AND PCMS_CHDOC_ACTION_DESC_4.CH_DOC_ID = PCMS_CHDOC_DATA_2.CH_DOC_ID)
There is a way to write such can also retrieve records that are null?AND (PCMS_CHDOC_ACTION_DESC_2.FILE_VERSION IN (SELECT MAX(FILE_VERSION) FROM PCMS_CHDOC_ACTION_DESC PCMS_CHDOC_ACTION_DESC_4 WHERE PCMS_CHDOC_ACTION_DESC_4.CH_UID = PCMS_CHDOC_DATA_2.CH_UID AND PCMS_CHDOC_ACTION_DESC_4.CH_DOC_ID = PCMS_CHDOC_DATA_2.CH_DOC_ID ) OR PCMS_CHDOC_ACTION_DESC_2.FILE_VERSION IS NULL)
or doesn't exist doesn't retrieve any record.
What do you mean by that?
* 009 *.Published by: 009 April 16, 2010 12:14 AM
-
Hi all
Oracle Version
11.2.0.1.0
I need to write a query update one table based on the following criteria:
The output I need is to update the table of trades with a description with the maximum date of trade_descp table based on a filter for example descp like "%M %.create table trades (tid number, descp varchar2(20)); create table trade_descp (tid number, aud_desc varchar2(20), c_date date) insert into trades values (1,NULL) insert into trades values (3,NULL) insert into trades values (4,NULL) insert into trade_descp values (1,'abdc(M)','1-Jan-2012') insert into trade_descp values (1,'abdc(M)','1-Jan-2013') insert into trade_descp values (1,'abdc(N)','1-Jan-2014')
There is an index on the column tid trade_descp table (with huge files).
Can this be achieved in direct SQL.
Thank you and best regards,
NikNikhil Juneja wrote:
but that is a full table of trade_descp table scan. Can we make us of the index built on the TID column?SQL> merge 2 into trades a 3 using ( 4 select tid, 5 max(aud_desc) keep(dense_rank last order by c_date) descp 6 from trade_descp 7 where aud_desc like '%M%' 8 group by tid 9 ) b 10 on ( 11 b.tid = a.tid 12 ) 13 when matched 14 then update 15 set a.descp = b.descp 16 / 1 row merged. SQL> select * 2 from trades 3 / TID DESCP ---------- -------------------- 1 abdc(M) 3 4 SQL> explain plan for 2 merge 3 into trades a 4 using ( 5 select tid, 6 max(aud_desc) keep(dense_rank last order by c_date) descp 7 from trade_descp 8 where aud_desc like '%M%' 9 group by tid 10 ) b 11 on ( 12 b.tid = a.tid 13 ) 14 when matched 15 then update 16 set a.descp = b.descp 17 / Explained. SQL> @?\rdbms\admin\utlxpls PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------------------------------------------- Plan hash value: 1775522890 ---------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------------- | 0 | MERGE STATEMENT | | 2 | 48 | 5 (20)| 00:00:01 | | 1 | MERGE | TRADES | | | | | | 2 | VIEW | | | | | | | 3 | SORT GROUP BY | | 2 | 142 | 5 (20)| 00:00:01 | | 4 | NESTED LOOPS | | | | | | | 5 | NESTED LOOPS | | 2 | 142 | 4 (0)| 00:00:01 | | 6 | TABLE ACCESS FULL | TRADES | 3 | 111 | 3 (0)| 00:00:01 | |* 7 | INDEX RANGE SCAN | TRADE_DESCP_IDX1 | 3 | | 0 (0)| 00:00:01 | |* 8 | TABLE ACCESS BY INDEX ROWID| TRADE_DESCP | 1 | 34 | 1 (0)| 00:00:01 | ---------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 7 - access("TID"="A"."TID") 8 - filter("AUD_DESC" IS NOT NULL AND "AUD_DESC" LIKE '%M%') Note ----- - dynamic sampling used for this statement (level=2) 25 rows selected. SQL>
SY.
Maybe you are looking for
-
Kaspersky URL Advisor 8.0.6 causes Firefox 9.0.1 to hang during the visit of will and secure Web sites do not allow a redirect to another site. banking sites, facebook, auctionsniper, all these are affected.
-
where is my tab to manage bookmarks?
I'm trying to download a collection of bookmarks in my class of real estate CD. He said to me on the left click the 'manage bookmarks' in Firefox, which is clearly visible in the window on the CD tutorial. My Firefox has no such tab and I can not und
-
Hi all I'm having a problem with creation of UN ultiboard PCB. I placed a plan of mass on the top brass. In the classic view, it seems the entire PCB. In the 3D preview, it only covers certain areas... (Please see attached screenshot) Any idea on how
-
Hi Sir, Would like to know is my "hp x 2 m011tu split' able to add hard drive? THK & rgd! James
-
I have many adobe reader downloads on computer and when I try to delete the old ones I get box comes and says I need to check the hotfix package