How to find max based on 2 columns.
Hi I have a table where I have two fields of digital type (date and time)) (this field are not date format time but digital)Date is in column A and column B represent the time.
How can I find the maximum value of column A and with results for a Max find b.
example of
A - - - - - - - - - -B
101010-202020
101011-202021
101012-202021
101010-202022
101012-202020
......... ...........
I'm looking for is
A - - - - - - - - - - B
101012-202021
Thank you
with t as (
select 101010 a,202020 b from dual union all
select 101011,202021 from dual union all
select 101012,202021 from dual union all
select 101010,202022 from dual union all
select 101012,202020 from dual
)
select max(a) a,
max(b) keep(dense_rank last order by a) b
from t
/
A B
---------- ----------
101012 202021
SQL>
SY.
Published by: Solomon Yakobson, February 24, 2010 12:57
Tags: Database
Similar Questions
-
How to find a value in any column of the table - essentially a search
Hi guys,.
Thanks in advance for your help.
I'll try to find a value in any column of the table? How can I do?
An example of value would be "FEDERAL."
Using Oracle 11 g and SQL Developer.
Thank you
It's a question that is asked in the past several times (but not recently from what I remember).
Michaels has provided in the past, solutions which are quite clever, just using SQL...
10g of solution
Michaels > var val varchar2 (5)
Michaels > exec: val: = "Sub".
PL/SQL procedure successfully completed.Michaels > select distinct substr (: val, 1, 11) "keyword."
substr (table_name, 1, 14) "table."
substr (t.column_value.getstringval (), 1, 50) ' / value of the column.
CLO.
Table
(xmlsequence
(dbms_xmlgen.getxmltype ("select" | column_name))
|| 'from ' | table-name
|| ' where upper (')
|| column_name
|| ') as superior (' %' |: val)
|| '%'')'
) .extract (' LINES/rowset / * "")
)
) t
-where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'SERVICES')
order of the "Table".11g upwards
SQL > select table_name,.
column_name,
: search_string search_string.
result
from (select column_name,
table_name,
"ora: view("' ||) " table_name | "") / LINE /' | " column_name | "[ora:contains (text ()," %' |: search_string | ")]. (%») > 0]' str
CLO
where table_name in ('EMP', 'Department')),
XMLTable (columns str result varchar2 (10) path '.')
/TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
------------------------------ ------------------------------ -------------------------------- ----------
DEPT DNAME es RESEARCH
EMP ENAME es JAMES
EMP JOB es SALESMAN
EMP JOB es SALESMAN4 selected lines.
-
How to find the name of a column in a table
Hi all
I have a Table that contains approximately 100 columns.
I need to find the column name, to find in specific columns containing data like 'abc '.
Ex: I have a table like temp_table_name
the columns are col1, col2, col3, col4, col5, col6, col7, col8,.... col99
I'm looking for with data specific like 'abc '.
Need to find the name of the table column that contains data of 'abc '.
Please suggest me. How to find in a single query... :-)
Actually I'm looking through a column of the table as below
Select count (*) in the temp_table_name where col1 = 'abc '.
FOR I IN 1.20 LOOP
ln_num_of_rows: = 0;
lv_column_name_search: = "col" | I have;
lv_sql: = ' select count (*) in the temp_table_name where ' | lv_column_name_search | "= abc";
EXECUTE IMMEDIATE lv_sql INTO ln_num_of_rows;
IF ln_num_of_rows > 0
-column found in lv_column_name_search
EXIT;
END IF;
END LOOP;
But I'm gettig performance problem.
How can I do this in any other alternative way? could you suggest any way possible as soon as POSSIBLE.It's probably never going to be effective - realistic, you have to scan completes the picture.
You could probably improve a little things by doing something like
SELECT DISTINCT column_name FROM ( SELECT (CASE WHEN col1 = 'abc' THEN 'col1' WHEN col2 = 'abc' THEN 'col2' WHEN col3 = 'abc' THEN 'col3' ... WHEN col20 = 'abc' THEN 'col20' ELSE NULL END) column_name FROM table_name WHERE col1 = 'abc' OR col2 = 'abc' ... OR col20 = 'abc' )
but it's never going to be incredibly fast.
Justin
-
Hi all, I would like to know if someone has developed a script to find all tables containing the columns (fields) specific.
I'm on a migration project where I don't have access to the source of the DB, I just ask for queries and I to reflect all the tables DB containing specific data of organization.So the first step was to understand used tables and I get them, now I understand what tables have Org_id / Organization_ID and fields of the SOURCE of the LANGUAGE/LANGUAGE (source DB has much set Org and many languages also, so I need to filter the 100total 6ORG_ID and 2 languages of 8 total installed)
Can anyone help?
Thank you
Best regards
Pietro
Hello
You can see this:
Find all tables in db with the name of the column of a particular string?
Kind regards
MihaiF
-
ORA-01438: how to find the name of the column?
Hello
I'm trying to find the column which is causing ORA-01438 when inserting into a table.
The insertion is made by a C program that reads from a socket and written in an oracle 10 g database using Oracle Pro * C.
I tried to identify the column by printing the values (about 250) just before the insert statement is executed, but check these values has been a task heavy and error prone and did not help to correct the mistake (I found a bunch of values which out of reach, but changing these values has not resolved the issue).
Abandon this idea, I tried to track the session to help
(1) DBMS_SYSTEM. SET_SQL_TRACE_IN_SESSION,
(2) DBMS_MONITOR.session_trace_enable/disable and still
(3) change the context name system set events 10046 trace forever, level 12' and;
(4) alter system set sql_trace = true scope = mΘmoire;
DBMS_MONITOR.session_trace_enable only gave me a few tips (the insert statement) in a trace file. But it worked for a simple example of a test database.
When I try to turn on tracing on the database, where the error occurs, then I'm still not able to set SQL_TRACE in V$ SESSION true, even if no error is returned by the statement "DBMS_MONITOR.session_trace_enable". The value of SQL_TRACE in V$ SESSION does not change and I have no idea why. On the test database, it works fine and I can find the trace file in the user_dump_destination directory.
Anyone have any suggestions on how to fix this?
Any help is appreciated.
Thanks in advance!Just check this:
SQL > conn osama/osama ; SQL> create table test as select * from scott.dept ; SQL> select * from test ; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON SQL> alter system set events='1438 trace name Errorstack forever,level 10'; SQL> insert into test values (100000000000000000,'osama','JOR'); insert into test values (100000000000000000,'osama','JOR') * ERROR at line 1: ORA-01438: value larger than specified precision allowed for this column In Trace File : ORA-01438: value larger than specified precision allowed for this column Current SQL statement for this session: insert into test values (100000000000000000,'osama','JOR')
-
How to find max Crest audio audio tracks combined with the applied effects?
Hi all
I work in the CS5.5 body.
Often when I'm working on a timeline, I have two audio tracks of the same songs, one of the camera and the other a separate, synchronized sound recorder on the timeline, so that they combine into a single signal. Applied to these titles, I might have an effect filter or high-low pass EQ. Now, I know that the maximum peak of each track or the individual clips is easy to find using the "Gain Audio" menu item, which I hope is the equivalent of this item of menu but related to the final output after two signal tracks has been added and effects have all served? It is a task that is very painful to have to listen through the entire timeline to discover if the output goes into 0db, if there was a way I could locate on the timeline where the max output, which would definitively solve the problem.
Find the way to do this would literally save hours per project! It's the only thing that makes me groan inwardly when I perform the output volume, what I have to do most of the time.
If all goes well,
Peter.
I always put a compressor and - 1db limiter of ridges on the master to stop overmods.
-
How to find out based on all INDEXES, VIEWS,... a table?
How can I find out how much and what objects dependent (index, views...) has a certain myuser444.table123 TABLE?
Peteruser559463 wrote:
How can I find out how much and what objects dependent (index, views...) has a certain myuser444.table123 TABLE?Use the DBA_DEPENDENCIES and DBA_INDEXES. For example:
select type || ' ' || owner || '.' || name from dba_dependencies where referenced_owner = 'SCOTT' and referenced_name = 'EMP' and referenced_type = 'TABLE' union all select 'INDEX ' || owner || '.' || index_name from dba_indexes where owner = 'SCOTT' and table_name = 'EMP' / TYPE||''||OWNER||'.'||NAME ---------------------------- FUNCTION SCOTT.F1 VIEW SCOTT.EMP_VW INDEX SCOTT.PK_EMP INDEX SCOTT.EMP_IDX1 SQL>
SY.
-
How to find the name of the column in the tables
Hello..
Suppose that there are thousands of table in the database. Out of them a few tables contain the column name as 'ENTRY_BY '.
I want to know the tables that have columns like "ENTRY_BY".
... Please suggest for this query.
all_tab_cols
Select * from all_tab_cols
where column_name like ' % INPUT % ';
Post edited by: Rajavignesh
-
Re: How to get Max (all values of columns) records on a partition interval
Hello
We have table as above, IE. everyday, there are records at regular intervals of hours for different users.Hours Days Name used_size 1 01-09-012 R1 1100 10 01-09-012 R1 1150 15 01-09-012 R1 1160 23 01-09-012 R1 1200 1 01-08-012 R1 1600 10 01-08-012 R1 1700 15 01-08-012 R1 1800 23 01-08-012 R1 1500 1 01-09-012 J1 10 10 01-09-012 J1 20 15 01-09-012 J1 30 23 01-09-012 J1 60 1 01-08-012 J1 70 10 01-08-012 J1 5 15 01-08-012 J1 17 23 01-08-012 J1 22 Needed o/p: 23 01-09-012 R1 1200 23 01-08-012 R1 1500 23 01-09-012 J1 60 23 01-08-012 J1 22
I want to get a single record of every day for one hour on this day for all users.
Please let me know if my question was unclear?
-Thank youAnother way, maybe more simple here, here could be just group by user, day.
SELECT user, day, Max(hours) max_hours, Max (used_size) KEEP (DENSE_RANK LAST ORDER BY hours) mh_used_size FROM (table) GROUP BY user, day ORDER BY user, day
-
How to find the Union between the column in the table
Hello
I have the followin table and I want to find the union between the lines as below,
I need the result to be as below.create table test5 (tidset varchar2(200)); insert into test5 values('1;2;3;4;5;6;7;8;9;10;11;12;13;15;16;17;18;19;20'); insert into test5 values('1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20'); insert into test5 values('1;2;3;4;6;7;8;9;11;12;13;15;16;19;20'); insert into test5 values('1;4;6;10;6;11;12;13;14;15;16;17;18;19;20');
any help please,.1;4;6;11;12;13;15;16;19;20
Published by: user11309581 on November 17, 2011 21:32Always mention what version of oracle you are using.
The following query will give you the desired result oracle version 11g release 2.
Connected to Oracle Database 11g Release 11.2.0.2.0 SQL> SQL> with test5 as 2 ( 3 select '1;2;3;4;5;6;7;8;9;10;11;12;13;15;16;17;18;19;20' tidset from dual union all 4 select '1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20' from dual union all 5 select '1;2;3;4;6;7;8;9;11;12;13;15;16;19;20' from dual union all 6 select '1;4;6;10;6;11;12;13;14;15;16;17;18;19;20' from dual -- "END OF SAMPLE DATA" 7 ), all_items as 8 ( 9 SELECT regexp_substr(t.tidset, '[^;]+', 1, column_value) item 10 ,t.tidset 11 FROM test5 t 12 ,TABLE(CAST(MULTISET 13 (SELECT LEVEL 14 FROM dual 15 CONNECT BY LEVEL <= 16 length(regexp_replace(t.tidset, '[^;]')) + 1) AS 17 sys.odcinumberlist)) 18 ),item_counts as 19 ( 20 SELECT DISTINCT a.item 21 ,COUNT(DISTINCT a.tidset) over() total_tidset 22 ,COUNT(a.item) over(PARTITION BY a.item) item_occurance_count 23 FROM (SELECT DISTINCT item 24 ,tidset 25 FROM all_items) a 26 ) 27 SELECT listagg(item, ';') within GROUP(ORDER BY to_number(item)) common_items 28 FROM item_counts 29 WHERE total_tidset = item_occurance_count 30 ; COMMON_ITEMS -------------------------------------------------------------------------------- 1;4;6;11;12;13;15;16;19;20 SQL>
OR if you have any version of oracle less than 11g release 2 then replace below mentioned line
SELECT listagg(item, ';') within GROUP(ORDER BY to_number(item)) common_items
with this one
select xmlagg(xmlelement(c,item||';').extract('//text()') order by (to_number(item))) common_items
It is because the listagg function used in above query is not supported in versions of oracle 11.2 below.
I hope this helps.
-Gregory
Published by: Mohamed Diarra on November 18, 2011 01:05
Extra line to be changed for the oracle version lower than 11.2 -
How to find Max, Min and Avg generation of redo to a database
I'm trying to remake maximum, minimum and average, a database to generate daily. This information, as well as knowledge of
specific database will be useful for me to determine the log archiving directory space allocation is sufficient for our database activity.
I want to just make sure that the request is correct or not.
Select upper (B.HOST_NAME) HOST_NAME, upper (B.INSTANCE_NAME) INSTANCE_NAME, A.* FROM)
Select max (redo_in_gb) MAX_REDO_IN_GB, min (redo_in_gb) MIN_REDO_IN_GB, avg (redo_in_gb) AVG_REDO_IN_GB)
Select sum (blocks * block_size) /(1024*1024*1024) REDO_IN_GB, trunc (first_time) as "RUN_DATE"
v $ archived_log where trunc (first_time) > (select trunc (resetlogs_time) in v$ database_incarnation where status = 'CURRENT')
Trunc Group (first_time))) A, V$ INSTANCE B
Thank you
GuzYes, that sounds good.
-
How to find the name of the column to the attributes of the IOM?
What is the COLUMN_NAME for attributes 'Generated password' and 'Access Console Design' in OIM 11 g?
Also I can't find anywhere in FormMetaData.xml. A file that represents FormMetaData.xml in OIM11g?Sorry
Try USR_TYPE
-
How to concatenate values based on multiple columns of data duplicate in the loop
Hi all
Select '100' col_1, '111111' col2 of double
Union of all the
Select '100' col_1, '222222' col2 of double
Union of all the
Select '101' col_1, '333333' col2 of double
Union of all the
Select '102' col_1, '333333' col2 of double
I need to write by using cursor loop (configurable) so, it must concatenate col_1 or col_2
If,
In the table
col_1, col_2
100 111111
100 222222
101 333333
102 333333
Then
col_1, col_2
100 111111,222222
333333 101 102
Is it possible to compare and concatenate values in the loop
I have more than 4,000 bytes in the table of col_1,col_2 data values
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
Ok then:
create a type that makes "grouped" clob
CREATE or REPLACE TYPE clob_obj IS OBJECT
(
CLOB theClob
ORDER MEMBER FUNCTION equals (in_clob_obj IN clob_obj) RETURN NUMBER
member function getClobVal return clob)
/CREATE or REPLACE TYPE clob_obj BODY
IS
FUNCTION MEMBER ORDER is equal to (in_clob_obj IN clob_obj)
RETURN NUMBER
IS
BEGIN
RETURN sys.dbms_lob.compare (SELF.theClob, in_clob_obj.theClob);
END;
Member return clob getClobVal function
is
BEGIN
Return self.theClob;
end;
END;
/WITH conc_table AS (SELECT 1111 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL
SELECT 2222 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL
SELECT 3333 cust_id, cust_no 'ABC', '101010' ordr_no OF DOUBLE UNION ALL
SELECT cust_id 4444, "CCC" cust_no, ordr_no ' 123456' OF DOUBLE UNION ALL
SELECT cust_id 5555, "CCC" cust_no, '454545' ordr_no OF DOUBLE UNION ALL
Select cust_id 66666, "CCC" cust_no, ordr_no ' 77777' DOUBLE UNION ALL
SELECT cust_id, "CCC" cust_no, ordr_no ' 77777 66666' FROM DUAL)
SELECT rtrim (XMLAGG (XMLELEMENT (E, cust_id_no, ',')). EXTRACT ('customer_id //text()').getClobVal (),',')
clob_obj (ord_number) .getClobVal)
cust_num
FROM (SELECT cust_id_no
cust_num
rtrim (XMLAGG (XMLELEMENT (E, ord_num, ",")). EXTRACT ('//text ()') .getClobVal (), ',') ord_number
FROM (SELECT DISTINCT cust_id_no, cust_num, ordr_no AS conc_table FROM ord_num cust_no cust_id)
GROUP BY cust_id_no
cust_num)
GROUP BY clob_obj (ord_number)
cust_num;
I got the distinct in the select more intimate for no duplicate of the basetable is only sent to reunification of...
HTH
-
Find the name of the column in all tables
How to find the name of the column in all tables in the database for any column to reveal the name of the person?
We have over 1000 tables looking for.and in some places, the name column FNAME LNAME, First_NAME, DNAMEFor example we have Customer table, Table EMPLOYEE and the ORDER Table
--------------------------------
Customer table
--------------------------------LNMAE
EMPLOYEE table
EMP_ID
DEPT_NAME (we don't want this column as it is not a name column)
Last_name (he must propose this column because it is named)----------------------------
CONTROL Panel
-----------------------------
ORDER_ID
ORDER_NAME (we don't want this column as it is not a name column)
Last_name (he must propose this column because it is named)-------------------------
Dept table
-------------------------
Dept_ID
DEPT_NAME (we don't want this column as it is not a name column)Please advise...
Thank you.
Hello
What exactly do you do?
If you want to display the tables containing these columns, you can query the view data dictionary USER_TAB_COLS (or ALL_TAB_COLS, or, if you have privileges, DBA_TAB_COLS).
For example:
SELECT table_name, column_name
Of user_tab_cols
WHERE nom_de_colonne IN ('DNAME', 'FNAME', 'FIRST_NAME', 'LAST_NAME', 'LNAME') - or else
ORDER BY table_name, column_name
;
-
How to find the value max and min for each column in a table 2d?
How to find the value max and min for each column in a table 2d?
For example, in the table max/min for the first three columns would be 45/23, 14/10, 80/67.
Thank you
Chuck,
With color on your bars, you should have enough experience to understand this.
You're a loop in the table already. Now you just need a function like table Max and min. loop. And you may need to transpose the table 2D.
Maybe you are looking for
-
Satellite A60: Powersaver won't start no-error 0x7E
I tried to install the powesaver for my satellite A60. I downloaded the driver from the Toshiba website.The installation went well until the end. The following error (fatal) is currently showed: 0x7E. The powersaver does not start.Also it's unpossibl
-
Other Include directories in the construction or the installer
The engineer so I have to write this program hates digging around for files if the software specification call for several configuration files outside the root directory. C:/program name/System_Config C:/program name/Instrument_Config C:/program name
-
Compaq mini cq10 bios password rese
Hello I have a cq10 compaq mini and I lost the password at startup SN # CNU0052435 This is my work at home LOL helpme please I try to pass:e9l117va6b e9l13uvae9e9l113qb9o and no work
-
Computer is humming, fan turns on and the screen is blank when I start computer
This problem happens every 90 days. When I took the computer to the repair shop, he had no problem with him right there. If the computer remains stationary, the problem persists, but once it is moved in a certain way, it will start normally. Specifi
-
Is there a way to configure my laptop to start automatically when it's plugged in?
I want to make sure my laptop will automatically start the minute it is plugged. I use it a lot for work and would be handy when displaying presentations. Is it possible, without going through the BIOS (most old laptop - does not power options in the