To find the lowest salary from a table
hello guys,
i need to find the lowest salary from a table. whats the easy way to do this.
How do you handle ties?
If you want multiple rows returned when there are multiple people with the same salary
SELECT *
FROM(
SELECT a.*,
rank() over (order by salary desc ) rnk
FROM your_table a)
WHERE rnk = 1If you want to handle ties differently, use a different analytic function. Probably dense_rank or row_number.
Justin
Similar Messages
-
Finding the column names from a table.
I am on 10g
I would like to find out the columns of a table where there are null columns in a table.....this table contains about 300 + columns where i do not want to put where condition for all the columns
is there a way i can write a sql to find?
for a given table or the results set that i need to get, i will have same results for all the rows, so it
cant be like col1 is null on row1, but col2 is not null on row2 ...they are all identical....
example table, but it has 300 + cols
F_IND H_IND P_IND DMA_IND
N N
N N
N N
N N Thanksselect count(col1), count(col2), count(col3), ...
from your table;
The results with 0s are null throughout the table (or the table has no rows). -
Finding the lowest number from several columns
Hi all,
I'm analysing data from students' two years course where they had 4 units. What I'd like to be able to do is see at a glance which of the 4 units for each student was their lowest - therefore allowing me to see if one unit in particular was letting them down. see pic and the 4 highlighted columns.
I have got the info as a graph, but you have to look individual at each one.
Can anyone help with a formula that could present the results for each student by the column header. E.g. In column A is the student names and in column B is the name of the column they got the lowest mark (in this case MS1, MS2, MS3 or MS4). I would love to be able make this as will really help next year's cohort!
Best,
GregHi Greg,
Have a look at the SMALL function. It allows you to see the smallest, second smallest... value in a list.
The SMALL function returns the nth-smallest value within a set of numeric values. The smallest value is ranked number 1.
SMALL(value-set, ranking)
value-set: A collection of number values, date/time values, or duration values. All values must be of the samevalue type.
ranking: A number value representing the size ranking of the value you want to retrieve. ranking must be in the range of 1 to the number of values in the collection.
Type = in a cell to bring up the Functions Panel. Type small in the search box.
Regards,
Ian. -
Can we find the number of rows in table from the dump file
Hi All,
Can we find the number of rows in table from the dump file with out importing the table in to the database?
Please let me know ,if any option is there.
Thanks,
Kumar.<s>Try to import with option SHOW=Y, that should skip the number of rows which are into a table from a dump file.</s><br>
<br>
Nicolas.<br>
Oops, sorry, that doesn't show the number of lines...<br>
Message was edited by: <br>
N. Gasparotto -
How to find the costliest course from the below table.
dear experts,
please help me to find the costliest course from the below data
COURSE CCOST
pgdca 4500
dca 7200
mca 22000
dcp 5000
pgdca 4500
dap 6200
dcap 5200
hdcp 14000
pgdca 4500
dca&p 11000Then read the FAQ for how to post a question on the forum.
1. You didn't say anything about using an Oracle database or what your 4 digit version of Oracle is.
2. You didn't provide a table name, the table DDL or insert statements to create the table and data
3. You didn't post the queries that you tried to write and tell us whether they work or not.
4. You didn't tell us when this homework assignment is due or that you needed a query.
This isn't a coding service. The forum is to help you with questions or issues you are having with YOUR queries.
No one can write a query without having a table. If you want help post the info requested above. -
How to find the lowest grade for each student using a Select query?
Hey I'm having a bit of trouble here
I have this table
Student - Grade
John - 8
Richard - 9
Louis - 9
Francis - 5
John - 13
Richard - 10
Peter - 12
Grades can range from 0 to 20.
Name - varchar(50)
Grade - integer
I am trying to generate a SQL search to find each lowest grade for each student.
So far I have done:
select s.name,s.grade
from student s
where s.grade = (select min(grade) from student)
The result of that search returns me only the lowest grade of all the grades posted above, which is Francis - 5.
I want to find the lowest grade, but not only for Francis but also for every other student in the table.
How do I do that?
Thank you in advanced.ok,
Now we are moving into Analytic SQL:
with student as (select 'John' name, 8 grade, 'fail' result from dual union all
select 'John' name, 13 grade, 'pass' result from dual union all
select 'Francis', 5 grade, 'fail' from dual union all
select 'Peter', 12, 'pass' from dual)
-- End of your test data
SELECT name,
MAX (result) KEEP (DENSE_RANK FIRST ORDER BY grade) result,
MIN (grade) min_grade
FROM student
GROUP BY namePlease note that I passed ;)
Regards
Peter
To read more:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#SQLRF00641 -
How to find the longest record in a table?
Hello,
Is there a function to find the longest record in a table? Or is there a data dictionary that would tell you which record contains the longest data?
I have a table with five columns and one million records. I want to find the record (5 columns combined) with the longest data. Thank you.Dear watson2000!
The function "VSIZE" tells you the number of bytes in the internal representation of a column which means the size of a value within a column. An example of vsize can be found here:
[http://www.adp-gmbh.ch/ora/sql/vsize.html]
So I think you should try it with this query to get the size of the longest record:
SELECT MAX(VSIZE(column1)) +
MAX(VSIZE(column2)) +
MAX(VSIZE(column3)) +
MAX(VSIZE(column4)) +
MAX(VSIZE(column5)) AS "Maximum Row"
FROM your_table;To identify the longest record try like this:
SELECT rowid
FROM your_table
GROUP BY rowid
HAVING (MAX(VSIZE(column1)) +
MAX(VSIZE(column2)) +
MAX(VSIZE(column3)) +
MAX(VSIZE(column4)) +
MAX(VSIZE(column5))) = (SELECT MAX(VSIZE(column1)) +
MAX(VSIZE(column2)) +
MAX(VSIZE(column3)) +
MAX(VSIZE(column4)) +
MAX(VSIZE(column5))
FROM your_table;)I hope that these two queries could be of help to you.
yours sincerely
Florian W.
Edited by: Florian W. on 23.04.2009 20:53 -
How to find the level of each child table in a relational model?
Earthlings,
I need your help and I know that, 'yes, we can change'. Change this thread to a answered question.
So: How to find the level of each child table in a relational model?
I have a relacional database (9.2), all right?!
O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */
/↑\ Fks
O"O O" <-- level 2 for first table (circle)
/↑\ Fks
"o"o"o" <-- level 1 for middle table (circle)
↑ Fk
"º"Tips:
- each circle represents a table;
- red tables no have foreign key
- the table in first line of tree, for example, has level 3, but when 3 becomes N? How much is N? This's the question.
I started thinking about the following:
First I have to know how to take the children:
select distinct child.table_name child
from all_cons_columns father
join all_cons_columns child
using (owner, position)
join (select child.owner,
child.constraint_name fk,
child.table_name child,
child.r_constraint_name pk,
father.table_name father
from all_constraints father, all_constraints child
where child.r_owner = father.owner
and child.r_constraint_name = father.constraint_name
and father.constraint_type in ('P', 'U')
and child.constraint_type = 'R'
and child.owner = 'OWNER') aux
using (owner)
where child.constraint_name = aux.fk
and child.table_name = aux.child
and father.constraint_name = aux.pk
and father.table_name = aux.father;Thinking...
Let's Share!
My thanks in advance,
Philips
Edited by: BluShadow on 01-Apr-2011 15:08
formatted the code and the hierarchy for readbilityJustin,
Understood.
Nocycle not work in 9.2 and, even that would work, would not be appropriate.
With your help, I decided a much simpler way (but there is still a small problem, <font color=red>IN RED</font>):
-- 1
declare
type udt_roles is table of varchar2(30) index by pls_integer;
cRoles udt_roles;
begin
execute immediate 'create user philips
identified by philips';
select granted_role bulk collect
into cRoles
from user_role_privs
where username = user;
for i in cRoles.first .. cRoles.count loop
execute immediate 'grant ' || cRoles(i) || ' to philips';
end loop;
end;
-- 2
create table philips.root1(root1_id number,
constraint root1_id_pk primary key(root1_id)
enable);
grant all on philips.root1 to philips;
create or replace trigger philips.tgr_root1
before delete or insert or update on philips.root1
begin
null;
end;
create table philips.root2(root2_id number,
constraint root2_id_pk primary key(root2_id)
enable);
grant all on philips.root2 to philips;
create or replace trigger philips.tgr_root2
before delete or insert or update on philips.root2
begin
null;
end;
create table philips.node1(node1_id number,
root1_id number,
node2_id number,
node4_id number,
constraint node1_id_pk primary key(node1_id)
enable,
constraint n1_r1_id_fk foreign key(root1_id)
references philips.root1(root1_id) enable,
constraint n1_n2_id_fk foreign key(node2_id)
references philips.node2(node2_id) enable,
constraint n1_n4_id_fk foreign key(node4_id)
references philips.node4(node4_id) enable);
grant all on philips.node1 to philips;
create or replace trigger philips.tgr_node1
before delete or insert or update on philips.node1
begin
null;
end;
create table philips.node2(node2_id number,
root1_id number,
node3_id number,
constraint node2_id_pk primary key(node2_id)
enable,
constraint n2_r1_id_fk foreign key(root1_id)
references philips.root1(root1_id) enable,
constraint n2_n3_id_fk foreign key(node3_id)
references philips.node3(node3_id) enable);
grant all on philips.node2 to philips;
create or replace trigger philips.tgr_node2
before delete or insert or update on philips.node2
begin
null;
end;
create table philips.node3(node3_id number,
root2_id number,
constraint node3_id_pk primary key(node3_id)
enable,
constraint n3_r2_id_fk foreign key(root2_id)
references philips.root2(root2_id) enable);
grant all on philips.node3 to philips;
create or replace trigger philips.tgr_node3
before delete or insert or update on philips.node3
begin
null;
end;
create table philips.node4(node4_id number,
node2_id number,
constraint node4_id_pk primary key(node4_id)
enable,
constraint n4_n2_id_fk foreign key(node2_id)
references philips.node2(node2_id) enable);
grant all on philips.node4 to philips;
create or replace trigger philips.tgr_node4
before delete or insert or update on philips.node4
begin
null;
end;
-- out of the relational model
create table philips.node5(node5_id number,
constraint node5_id_pk primary key(node5_id)
enable);
grant all on philips.node5 to philips;
create or replace trigger philips.tgr_node5
before delete or insert or update on philips.node5
begin
null;
end;
-- 3
create table philips.dictionary(table_name varchar2(30));
insert into philips.dictionary values ('ROOT1');
insert into philips.dictionary values ('ROOT2');
insert into philips.dictionary values ('NODE1');
insert into philips.dictionary values ('NODE2');
insert into philips.dictionary values ('NODE3');
insert into philips.dictionary values ('NODE4');
insert into philips.dictionary values ('NODE5');
--4
create or replace package body philips.pck_restore_philips as
procedure sp_select_tables is
aExportTablesPhilips utl_file.file_type := null; -- file to write DDL of tables
aExportReferencesPhilips utl_file.file_type := null; -- file to write DDL of references
aExportIndexesPhilips utl_file.file_type := null; -- file to write DDL of indexes
aExportGrantsPhilips utl_file.file_type := null; -- file to write DDL of grants
aExportTriggersPhilips utl_file.file_type := null; -- file to write DDL of triggers
sDirectory varchar2(100) := '/app/oracle/admin/tace/utlfile'; -- directory \\bmduhom01or02
cTables udt_tables; -- collection to store table names for the relational depth
begin
-- omits all referential constraints:
dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'REF_CONSTRAINTS', false);
-- omits segment attributes (physical attributes, storage attributes, tablespace, logging):
dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SEGMENT_ATTRIBUTES', false);
-- append a SQL terminator (; or /) to each DDL statement:
dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'SQLTERMINATOR', true);
-- create/open files for export DDL:
aExportTablesPhilips := utl_file.fopen(sDirectory, 'DDLTablesPhilips.pdc', 'w', 32767);
aExportReferencesPhilips := utl_file.fopen(sDirectory, 'DDLReferencesPhilips.pdc', 'w', 32767);
aExportIndexesPhilips := utl_file.fopen(sDirectory, 'DDLIndexesPhilips.pdc', 'w', 32767);
aExportGrantsPhilips := utl_file.fopen(sDirectory, 'DDLGrantsPhilips.pdc', 'w', 32767);
aExportTriggersPhilips := utl_file.fopen(sDirectory, 'DDLTriggersPhilips.pdc', 'w', 32767);
select d.table_name bulk collect
into cTables -- collection with the names of tables in the schema philips
from all_tables t, philips.dictionary d
where owner = 'PHILIPS'
and t.table_name = d.table_name;
-- execution
sp_seeks_ddl(aExportTablesPhilips,
aExportReferencesPhilips,
aExportIndexesPhilips,
aExportGrantsPhilips,
aExportTriggersPhilips,
cTables);
-- closes all files
utl_file.fclose_all;
end sp_select_tables;
procedure sp_seeks_ddl(aExportTablesPhilips in utl_file.file_type,
aExportReferencesPhilips in utl_file.file_type,
aExportIndexesPhilips in utl_file.file_type,
aExportGrantsPhilips in utl_file.file_type,
aExportTriggersPhilips in utl_file.file_type,
cTables in out nocopy udt_tables) is
cDDL clob := null; -- colletion to save DDL
plIndex pls_integer := null;
sTableName varchar(30) := null;
begin
for i in cTables.first .. cTables.count loop
plIndex := i;
sTableName := cTables(plIndex);
* Retrieves the DDL and the dependent DDL into cDDL clob *
* for the selected table in the collection, and writes to file.*
begin
cDDL := dbms_metadata.get_ddl('TABLE', sTableName, 'PHILIPS');
sp_writes_ddl(aExportTablesPHILIPS, cDDL);
exception
when dbms_metadata.object_not_found then
null;
end;
begin
cDDL := dbms_metadata.get_dependent_ddl('REF_CONSTRAINT', sTableName, 'PHILIPS');
sp_writes_ddl(aExportReferencesPhilips, cDDL);
exception
when dbms_metadata.object_not_found2 then
null;
end;
begin
cDDL := dbms_metadata.get_dependent_ddl('INDEX', sTableName, 'PHILIPS');
sp_writes_ddl(aExportIndexesPhilips, cDDL);
exception
when dbms_metadata.object_not_found2 then
null;
end;
begin
cDDL := dbms_metadata.get_dependent_ddl('OBJECT_GRANT', sTableName, 'PHILIPS');
sp_writes_ddl(aExportGrantsPhilips, cDDL);
exception
when dbms_metadata.object_not_found2 then
null;
end;
begin
cDDL := dbms_metadata.get_dependent_ddl('TRIGGER', sTableName, 'PHILIPS');
sp_writes_ddl(aExportTriggersPhilips, cDDL);
exception
when dbms_metadata.object_not_found2 then
null;
end;
end loop;
end sp_seeks_ddl;
procedure sp_writes_ddl(aExport in utl_file.file_type,
cDDL in out nocopy clob) is
pLengthDDL pls_integer := length(cDDL);
plQuotient pls_integer := null;
plRemainder pls_integer := null;
begin
* Register variables to control the amount of lines needed *
* for each DDL and the remaining characters to the last row. *
select trunc(pLengthDDL / 32766), mod(pLengthDDL, 32766)
into plQuotient, plRemainder
from dual;
* Join DDL in the export file. *
* ps. 32766 characters + 1 character for each line break. *
-- if the size of the DDL is greater than or equal to limit the line ...
if plQuotient >= 1 then
-- loops for substring (lines of 32766 characters + 1 break character):
for i in 1 .. plQuotient loop
utl_file.put_line(aExport, substr(cDDL, 1, 32766));
-- removes the last line, of clob, recorded in the buffer:
cDDL := substr(cDDL, 32767, length(cDDL) - 32766);
end loop;
end if;
* If any remains or the number of characters is less than the threshold (quotient = 0), *
* no need to substring. *
if plRemainder > 0 then
utl_file.put_line(aExport, cDDL);
end if;
-- record DDL buffered in the export file:
utl_file.fflush(aExport);
end sp_writes_ddl;
begin
-- executes main procedure:
sp_select_tables;
end pck_restore_philips;<font color="red">The problem is that I still have ...
When creating the primary key index is created and this is repeated in the file indexes.
How to avoid?</font> -
How to find the data loaded from r/3 to bw
hi
how to find the data loaded from r/3 to bw is correct . i am not able to find which feild in the query is connected to which feild in the r/3 . where i am geting the data from r/3 . is there any process to find which feild and table the data is comming from . plz help
thanks in advance to u allHi Veda ... the mapping between R/3 fields and BW InfoObjects should take place in Transfer Rules. Other transformation could take place in Update Rule.
So you could proceed this way: look at InfoProvider Data Model and see if the Query does perform any calculation (even with Virtual keyfigures / chars). Than go back to Update Rules and search for other calculation / transformation. At least there are Tranfer Rule and eventually DataSource / Extraction Enhancements.
As you can easily get there are many points where you have to look for ... it's a quite complex work but very usefull.
Once you will have identified all mappings / transfromation see if BW data matchs R/3 (considering calculations ...)
Good job
GFV -
How to find the avg salary of first 3 employees based on each department?
how to find the avg salary of first 3 employees based on each department?
Hi,
Do you mean something like this?
with a as
select
deptno
,sal
,row_number() over ( partition by deptno order by sal desc) rn
from
emp
select
deptno
,round(avg(sal)) avg_sal_of_top_3
from
a
where
rn <= 3
group by
deptno
order by
deptno
DEPTNO AVG_SAL_OF_TOP_3
10 2917
20 2992
30 1983
If not please give more details.
Regards,
Peter -
How to find the structural difference between two tables
Hi all,
How to find the structural difference between two tables .
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
Thanks,
P Prakashyou could try something similar to this, for each table pair that you want to compare:
SELECT 'TABLE_A has these columns that are not in TABLE_B', DIFF.*
FROM (
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_A'
MINUS
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_B'
) DIFF
UNION
SELECT 'TABLE_B has these columns that are not in TABLE_A', DIFF.*
FROM (
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_B'
MINUS
SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
FROM all_tab_columns
WHERE table_name = 'TABLE_A'
) DIFF;that's assuming, column_name, data_type and data_length are all you want to compare on. -
How to get second maximum salary from employee table(sql query)
how to get second maximum salary from employee table(sql query)
dude there is no matter of structure .........that user already said its from employee table ...............its basic table in sql and there is no need to specify the table structure
.........i think u got my point I think you are the one who didn't understand Sarma's point.
Give a man a fish and you feed him once. Teach a man how to fish and you feed him a life long.
>
and the query is
select max(sal) from emp where sal<(select max(sal)
from emp);
this will give the 2nd max salary from the emp tableBtw: You solution is bad, because it needs to scan and sort the table emp twice. And a better solution has been given already.
Message was edited by:
Sven W. - reordered statements -
How to find the Purchase Orders from Sales Order number
Hi ...
Is there a way to write a query to find the Purchase orders
from the Sales Order number ....
I have notice the table POR9 (Purchase Order - base Document)
but it seems to be empty.
Could you please help me to figure this out,
Thank you very much
Kind Regards
Sanjayahi,
u did mistake in selecting the table
SELECT T0.DocNum FROM ORDR T0 for sales order
SELECT T0.DocNum FROM OPOR T0 for purchase order
how to find the table in SAP B1.
go to above menu view => system information. tick it(or select it)
then below status bar u can see the table and field name.
open the required form and just keep the mouse cursor on any field.
you can see the table and field name below.
hope now u can able to track the table name.
regards
sandip -
How to find the group ids from which the mail has been sent
Hi,
We are able to see the list of mails have been sent to respective mail ids with the help of tcode SOST.
Is there any way to find through which group ids the mails have been sent.
Tehe details showing as the mail has been sent by Batchusr.
Please suggest how to find the group id from where the the mails have been triggered.
Regards,
Jena.Hi
This is not helpfull
If you open any notification QM03, there you will get tab " Action Log"
If you click on action log , there are two fileds
Date and time for task release
I want to fetch these fileds in one of Z report.
I am unable to find table name for these two fileds
Task release Date
Task release Time
Can we add 'QN CHANGE DATE' parameter in the selection screen (just like QN creation date) w/ range? The user want to run the report by QN change date as well. -
How to deselect the Radio button from htmlb.table.TableView
Hi Experts,
Could you please help me, how to seselect the Radio button from htmlb.table.TableView?
<hbj:tableView
id="tbvCustomer"
model="mcBean.csModel"
design="ALTERNATING"
headerVisible="TRUE"
footerVisible="TRUE"
navigationMode="BYPAGE"
selectionMode="SINGLESELECT"
fillUpEmptyRows="FALSE"
headerText="Searchresults"
visibleRowCount="10"
onNavigate="CustomerSearchNavigate"
visibleFirstRow="<%=mcBean.getCsVisibleFirstRow() %>">
Problem: After searching and selecting the Customer in the table, then again we are searching for another customer. After that the searched customer is displaying in the Table. By default the table Radio button is selected. Because for first Customer we have selected the Radio button. How we can deselect the FRadio button while searching for another Customer.
Thanks In Advance.
Regards,
Vijay.I think it is <2095>.
In SmartForms, go to your text window.
Use the icon on the top left of the text window to switch to the old editor.
INSERT -> CHARACTERS -> SAP ICONS.
Do a FIND on "radio". It's called ICON_WD_RADIO_BUTTON_EMPTY.
Maybe you are looking for
-
Bridge CS4 showing generic icon for TIF... sometimes
I recently installed CS4 and Bridge, all updated to the latest versions. Here's the scenario: Desktop running Windows XP Home with all updates and patches applied running CS4. Laptop running Nikon Scan to acquire scans using Coolscan 5000. Both PCs o
-
I'm having trouble staying connected to the internet
I'm having trouble "staying" connected to the internet.
-
Delivery tolerance (based on the delivery date)
Dear All How to maintain delivery tolerance (based on the delivery date) in Purchasing Order Would you help me, please thanks imron
-
Hi ! I have a problem, I'm creating an addins which create PO. I want to launch workflow when I create purchase ordre, but, nothing happens at PO creation. Is there something to do ? Or is it automatic ?
-
DW Template and table jump from page to page
Hi, I have put together a rather quick, basic site for a friend in need (meaning=bare bones here to get it started faster). It's template-based and table-based. The site is generally working okay except that the content in terms of the tables jumps s