How To Sort Data

Nov 23, 2008

I have the following three tables:

Buyer:
BuyerID
Name

Trans:
TransID
BuyerID

Trans_Item:
Qty
Price
BuyerID
TransID

I need to figure what buyer has bought the most things. I have a function already determines the amount each buyer has bought.

So that is done. I need to order this by buyerid. How do I sort something like that? ORDER BY and GROUP BY do not work.

View 2 Replies


ADVERTISEMENT

SQL & PL/SQL :: Sort Alphanumeric Data

Nov 20, 2008

I have an urgent request which is pending with the following problem.

Problem :

I have a table which contains data of various datatypes like alphanumeric,varchar and number.

Now my query is " how to sort the data of the table using alphanumeric field"

How to select the data in a required(MyRequirement) sort order.

Data
============
12.4PI1
12.4
12.2
12.4T
12.3PI1

[Code]....

afterSorting(which I am getting Now)
============
12.2
12.3PI1
12.4
12.4PI1
12.4PI10
12.4PI11

[Code]...

MyRequirement
===============
12.2
12.3PI1
12.4
12.4PI1
12.4PI2
12.4PI3
12.4PI10

[Code]..

Means it has to sort the data order by lefthand side of PI and also righthand side of PI.

Pls check the attachment if you are not getting the above data in correct order.

View 22 Replies View Related

Forms :: Sort Data In Execute Query Mode During Runtime?

Nov 15, 2012

How can i sort data in the execute Query mode during runtime,i have a columns which has number, char and date field.

This below data is fetched in execute query from a table;
x1 x2 x3
1343 adfa 11/14/2012
1353 adfa 11/11/2012
1333 adfa 11/10/2012
1333 adfa 11/12/2012
1353 adfa 11/09/2012

now i like to sort like this below;

x1 x2 x3
1343 adfa 11/09/2012
1353 adfa 11/10/2012
1333 adfa 11/11/2012
1333 adfa 11/12/2012
1353 adfa 11/13/2012

how to do it?

View 4 Replies View Related

SQL & PL/SQL :: Count And Sort?

Mar 10, 2010

I am running this query but am not getting data that is correct.

SELECT a.prod_id, a.prod_name, a.artist_name, COUNT(*)
FROM po_my_purchase_tb a, cm_track_tb b
WHERE a.prod_id = b.prod_id and b.GNR_CD = 'GR000017' AND a.purchase_date > '10-FEB-10' AND ROWNUM<50
GROUP BY a.prod_id, a.prod_name, a.artist_name, a.buy_seq
ORDER BY COUNT(*) desc

View 8 Replies View Related

SQL & PL/SQL :: Sort By Best Match

Jan 20, 2012

Suppose I have a table in which I have first_name, last_name, dob. Now I have to fetch on the basis of first_name=some_value, last_name=some_value and dob=some_date. I want to sort it on the basis of exactly fetched values. Let me take an example-

test table contains-

first_name last_name dob
---------- --------- ----
Manu Batham 02-Feb-1988
Manu Sharma 01-Jul-1987
Avinash Pandey 03-Feb-1988
Ankit Gupta 02-Feb-1988
Manu Aggrawal 02-Feb-1988
Manu Batham 20-Jan-1985
Sikha Batham 17-Apr-1988

Now if I give parameters-

first_name='Manu'
last_name='Batham'
dob='02-Feb-1988'

then my result should be like below-

result-

first_name last_name dob
---------- --------- ----
Manu Batham 02-Feb-1988
Manu Aggrawal 02-Feb-1988
Manu Batham 20-Jan-1985
Manu Sharma 01-Jul-1987
Ankit Gupta 02-Feb-1988
Sikha Batham 17-Apr-1988

My result is based on the approach-
if matched first_name, last_name, dob --> 1st prefrence in order
if matched first_name, dob --> 2nd prefrence in order
if matched first_name, last_name --> 3rd prefrence in order
if matched last_name, dob --> 4th prefrence in order
if matched first_name --> 5th prefrence in order
if matched last_name --> 6th prefrence in order
if matched dob --> 7th prefrence in order

I designed the following query for the same-

Select first_name,last_name,dob,1 "Order" from test Where
first_name='Manu' and
last_name='Batham' and
dob=to_date('02/02/1988','dd/mm/yyyy')
union
Select a,b,c,2 from test Where
[code]......

I know that this is not the best possible solution as the table is very big and doing so many hits on that table will certainly decrease the performance.

View 19 Replies View Related

Split Value And Sort By Lastname?

Dec 11, 2008

I have a field called fullname that outputs records with fullname of people.

Here is what I have when I do this sql:

Select fullname from tableOne;

John Jones
Bill Aronsen
Sam Baker
George Williams
Dave Smith

I would like to sort in order of last name but cant figure out how to do the sql:

Bill Aronsen
Sam Baker
John Jones
Dave Smith
George Williams

View 1 Replies View Related

SQL & PL/SQL :: Sort On Multiple Columns

Jun 16, 2010

how does sorting on multiple columns work

suppose my query is

select * from person order by first_name desc
and sys_person_id asc

this query works , but is this write way to sort on multiple column ?

View 12 Replies View Related

SQL & PL/SQL :: Trigger To Sort Out Positions

Jun 22, 2011

I want a trigger i have made a software abut school system i need a trigger to sort out the positions...if total number like 100,99,98 than in positions column 1,2,3 but if total marks same like 100,100 in position column shows 1,2..i need if the marks are same than in position column also same like if marks 100,100 in position column shows 1,1

View 3 Replies View Related

PL/SQL :: Sort Column Based On Value

Oct 17, 2012

Query result gives out put like in the following order

CITY NAME
CHENNAI
DELHI
LONDON
RIO DE GENARO

How to get output in the following sort order

LONDON
CHENNAI
DELHI
RIO DE GENARO

i dont want to hardcode the column values ..it will be great if i get option to generate dynamically.

View 9 Replies View Related

Oracle Table Sort Order

Jul 16, 2010

I know the only way to guarantee a specific sort order result when querying table is by using the order by clause. However, I have an issue where I do not have access to the code for the web user interface of a very lightly used interface (has two users). In that user interface is a drop down box that is populated by a table - one table. The drop down box is populated by the query "select [column name] from [table name]". Right now there are 400+ rows in that table total, so it's small but not having the items ordered is a pain.

I would like to alter something on the db side so the result of "select [column name] from [table name]" is an ordering by the column descending. I don't want the sort order to be the same for all queries (including joins and all) just want to control the order for that one query. It is Oracle9i.

View 1 Replies View Related

Forms :: Sort On Non Database Column

Jan 26, 2011

I have a master detail form that presents a list of 22 items that can be checked or unchecked depending on whether the test is needed.

The issue I have is trying to order or sequence the list in a specific order without a database column.

Here is the code I am trying to use in a post query trigger:

CASE :SAMPLE_TESTS.TESTCODE
when 'L001'
then :SAMPLE_TESTS.SEQ := '02' || :SAMPLE_TESTS.TESTCODE;
when 'L002'
then :SAMPLE_TESTS.SEQ := '03' || :SAMPLE_TESTS.TESTCODE;
when 'L003'
then :SAMPLE_TESTS.SEQ := '04' || :SAMPLE_TESTS.TESTCODE;

[Code]..

The non-database field is character with a length of 6.

When I try to use this field in the order by property of the data block it is unable to perform query.

Is there another way?

View 1 Replies View Related

SQL & PL/SQL :: Using Union Operator And Sort By Month?

Jan 10, 2012

i got the data like

select * from Table1
SNO Name B_MONTH
--------------------
101 A Mar
102 B Jan
103 C Feb
104 D Apr
105 f May
106 G Jun

Select * from Table2

107 H Dec
108 I Aug
109 J Oct
110 L Jul
111 M Sep
112 N Nov

select * from table1 union select * from table2 order by 3

The B_MONTH column is in Varchar2. Expected output should be

Output:

Jan
Feb
Mar
Apr
.
.
.
.
Nov
Dec

View 8 Replies View Related

SQL & PL/SQL :: Sort Name Field In Dictionary Order?

Dec 12, 2010

I have a name field like below; i need a query to display the name field in alphabetical order like in dictionary.

Emp Name
--------
Sam
John
Noel
Alen
Saaem

output would be
---------------
Alen
John
Noel
Saaem
Sam

View 5 Replies View Related

SQL & PL/SQL :: What Is Hash Join And Sort Merge

Jun 12, 2012

I tried to search on google for "Hash Join" And "Sort Merge". But unfortunatly i am unable to understand that articles. "Hash join" And "Sort Merge".

View 3 Replies View Related

PL/SQL :: How To Sort Inside Column Values (VC2)

Jan 14, 2013

I need to sort values inside a column. Data in column is concat with '|' (pipe). There could be 1 to many values in one column.

The order of the rows is not relevant here.

Test case:
-------------

create table t1 (col1 varchar2(100));

insert into t1 values ('H302|H411|H317|H314|H312');

insert into t1 values ('H315|H410|H400|H318');

insert into t1 values ('H226|H400|H331|H318|H317|H315|H310|H301');

insert into t1 values ('H301');

commit;

select col1 from t1;

COL1
----------------------------------------
H302|H411|H317|H314|H312
H315|H410|H400|H318
H315|H318
H301
H226|H400|H331|H318|H317|H315|H310|H301

Need is this:

COL1
----------------------------------------
H302|H312|H314|H317|H411
H315|H318|H400|H410
H315|H318
H301
H226|H301|H310|H315|H317|H318|H331|H400

View 4 Replies View Related

PL/SQL :: Scalar Subquery To Sort Column

Jul 7, 2012

am using a scalar subquery in order to sort by department_name column. My sql statement is like this:

select employee_id,last_name
from employees e
order by
(select department_name
from departments d
where d.department_id= e.department_id)

i want to display also the department_name in my output.

select employee_id,last_name,
(select department_name
from departments d
where d.department_id= e.department_id) department_name,department_id

[Code]...

the result is sorted and name is also displaying.but am not getting the output properly.

result is like this:

EMPLOYEE_ID LAST_NAME DEPARTMENT_NAME DEPARTMENT_ID
--------------------------------------------------------------------------------------------------------
205 Higgins Accounting 110
206 Gietz Accounting 110
200 Whalen Administration 10
107 Lorentz IT 60
105 Austin IT 60
103 Hunold IT 60
104 Ernst IT 60
106 Pataballa IT 60

am getting the first three line.but as 5 worker are in IT department so in that case how result is sorted..

View 1 Replies View Related

PL/SQL :: Query Sort By Case Sensitive

Oct 1, 2013

I am using oracle database 11g.My use case is I do have a table with following valuesTable name -test

product id     productsortdescription
H58098        ACETAMIDOHYDROXYPHENYLTHIAZOLE
043994         Alloy .MM.INTHICK  My query is  
select * from test order by productsortdescription;  this query gives result as is like
product id     productsortdescription
H58098        ACETA

product id     productsortdescription
H58098        ACETAMIDOHYDROXYPHENYLTHIAZOLE
043994         Alloy .MM.INTHICK
MIDOHYDROXYPHENYLTHIAZOLE
043994         Alloy .MM.INTHICK

but Expected output/result should be like below: 

product id     productsortdescription

043994     Alloy .MM.INTHICKH58098      ACETAMIDOHYDROXYPHENYLTHIAZOLE as All and ACE

in productsortdescriptionl is in small case than C. NLS Session parameters are as following

SELECT * from NLS_SESSION_PARAMETERS;
 NLS_LANGUAGE    AMERICANNLS_TERRITORY    AMERICANLS_CURRENCY    $NLS_ISO_CURRENCY    AMERICANLS_NUMERIC_CHARACTERS    .,
NLS_CALENDAR    GREGORIANNLS_DATE_FORMAT    DD-MON-RRNLS_DATE_LANGUAGE    AMERICANNLS_SORT    BINARYNLS_TIME_FORMAT    HH.MI.SSXFF AMNLS_TIMESTAMP_FORMAT    DD-MON-RR HH.MI.SSXFF AMNLS_TIME_TZ_FORMAT    HH.MI.SSXFF AM TZRNLS_TIMESTAMP_TZ_FORMAT    DD-MON-RR HH.MI.SSXFF AM TZRNLS_DUAL_CURRENCY    $NLS_COMP    BINARYNLS_LENGTH_SEMANTICS    BYTENLS_NCHAR_CONV_EXCP    FALSE 

View 5 Replies View Related

SQL & PL/SQL :: Sort A Comma Separated String?

Aug 4, 2008

I have a requirement to sort a comma seperated string. For example if I pass '1234,432,123,45322,56786' as string, then it should return '123,432,1234,45322,56786', after sorting the numbers inside the string.

I have done it creating Global Temporary table. Is there a way without creating the Temp table. I understand I can write the whole logic to sort and append the string, but if there is any direct way.

CREATE GLOBAL TEMPORARY TABLE TEMP_TAB(COL1 VARCHAR2(100)) ON COMMIT DELETE ROWS;
CREATE OR REPLACE FUNCTION func_sort_string(pi_string IN VARCHAR2, pi_delimiter IN VARCHAR2 DEFAULT ',')
RETURN VARCHAR2 IS
PRAGMA AUTONOMOUS_TRANSACTION;
l_str VARCHAR2(2000) DEFAULT pi_string || ',';

[code]...

View 26 Replies View Related

SQL & PL/SQL :: How To Sort Date By Month (JAN) And Year (2009)

Jun 4, 2010

I've done this once before, but can't seem to find the sql.

How can I sort by month and year on a column called ex: TEST_dATE

JAN 2007
FEB 2007
APR 2008
SEP 2009
OCT 2009
FEB 2010
JUN 2010

View 15 Replies View Related

SQL & PL/SQL :: How To Sort Query Based On Financial Year

Jun 12, 2012

Haw to sort the data based on financial year.

For example Indain Fiscal year 01-Apr-2010 to 31-Mar-2011

Apr2010 -1
May2010 -2
.
.
.
.
Feb2011-11
Mar2011-12

I had given a query..for Quarter idendification

SELECT distinct
'Qtr'
|| CASE
WHEN PERIOD BETWEEN TO_DATE ('01-04-2010', 'DD-MM-YYYY')
AND ADD_MONTHS (TO_DATE ('01-04-2010', 'DD-MM-YYYY')-1, 3)

[code].....

View 2 Replies View Related

Forms :: How To Use Multiple Buttons To Sort Columns

May 6, 2010

I am maintenancing a form which I have to add buttons as headers that will sort each column's data either in desc or asc order when the user click each button. How is this done? I need to know what built-in function that will closely do this or cod.

View 19 Replies View Related

SQL & PL/SQL :: Sort Names In Table Without Using Group By Command

Jul 3, 2011

how to sort the names in table without using group by command?.

View 3 Replies View Related

Create A Separate Sort Order Column On Table

Oct 31, 2006

I have data that i am sorting, the data is mostly numeric (format of XXX-1234). is there any way to have my query sort xxx-1000 AFTER xxx-999? right now i am thinking i will have to create a separate sort order column on my table.

View 2 Replies View Related

Performance Tuning :: WINDOW SORT - Reduce Time?

Nov 30, 2011

In my insert query, Window sort takes longer time i.e. 93% of total execution time, How do i reduce this time? are there any tuning parameters availabe for this?

View 5 Replies View Related

Generate CASE WHEN Query With ORDER BY Involving Secondary Sort

Oct 31, 2012

Below Query I understand is improper wrt syntax. Need to modify query to fetch correct result for me.

select * from tableA order by
case when a is not null then
a DESC
else
b DESC, c DESC END

Note: DESC or ASC is dynamic coming from java-code.

View 3 Replies View Related

Sort Ascending Or Descending Of Last Total Column Of Matrix Report R6i

Nov 3, 2010

How can I Sort Ascending or Descending of Last Total Column of Matrix Report R6i i.e. F_SumsalPerempno, summing total salary of each empno at end of each row.

I need the employee paid highest amount of total salary during the year to appear on first row, while months to display as per original order.

View 2 Replies View Related

Sort Through Schema Tables To Find If Particular Vendor Number Exist

Nov 14, 2006

I would like to be able to sort through a schema's tables to find if particular vendor numbers exist. The decode cross tab works fine, except that it needs static data for each table. How can I code a PL/SQL to populate the table_name and give a count for each row? See example below:

col table_name format a15
set numwidth 10
set lines 1000
set pages 50

select b1.table_name,
count(case when a.vendor='86444' then 1 else null end) "86444",
count(case when a.vendor='86445' then 1 else null end) "86445",
count(case when a.vendor='86469' then 1 else null end) "86469",
count(case when a.vendor='86470' then 1 else null end) "86470",
[code]........

View 1 Replies View Related

Reports & Discoverer :: Group Report From View Sort Differently?

May 20, 2011

I encountering while giving ORDER BY CLASS at report query.

View was created from Master and Detail table with simple join after this i created group above report with order by ID (Varchar2 , Values like 0010101001) but in report it order ruffly( not ascending or descending but randomly) .

View 3 Replies View Related

SQL & PL/SQL :: Delete Last N Sets Of Rows Of A Table With Same Dates In Sort Field

Mar 15, 2013

I know how to select the last N sets of rows, using DENSE_RANK - where multiple rows have the same timestamp but I want to only select those rows which do NOT have the top 2 unique timestamps.

i.e.:

SELECT *
FROM ( SELECT DENSE_RANK() OVER (ORDER BY myTimestamp DESC) DENSE_RANK, HISTORYID, USER_ID, myTimestamp, STATUS, FROM TXN_HIST)
WHERE DENSE_RANK > 2 order by myTimestamp DESC, HISTORYID, USER_ID;

But how do I DELETE these same rows?

View 3 Replies View Related

Application Express :: Interactive Report Sort Text As Number?

Jul 10, 2012

it is possible in an Apex interactive report to sort text as number?

For example, a series of text rows:

4
10
2

would sort as:

10
2
4

if it were text. What I would like to see is:

2
4
10

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved