473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Urgent Query

Hi...

I have a table with the below records and I need to group by the name
and order by the Code

Code Name
----- ----------
P 1 dddd
F 1 ffff
A 1 wwww
I 2 AAA
R 1 ffff
Z 2 AAA
Result should be such that Code with A should be sorted in the Group
with 1 and so on
Name Code
----------- -----
1 wwww A
1 ffff F
1 dddd P
1 ffff R
2 AAA I
2 AAA Z

I have written this query but it gives me the below output :

SELECT Name,Code FROM (SELECT ROW_NUMBER() OVER(PARTITION BY
Name,Code) AS rn, Name,Code FROM tablename ) AS T WHERE rn = 1 order BY
Name
Name Code
----------- -----
1 dddd P
1 ffff F
1 ffff R
1 wwww A
2 AAA I
2 AAA Z

I have tried all combintaions but still am not able to group by the
Code

Thanks.....
RaiNDeEr

Dec 5 '06 #1
3 2021
rAinDeEr wrote:
Hi...

I have a table with the below records and I need to group by the name
and order by the Code

Code Name
----- ----------
P 1 dddd
F 1 ffff
A 1 wwww
I 2 AAA
R 1 ffff
Z 2 AAA
Result should be such that Code with A should be sorted in the Group
with 1 and so on
Name Code
----------- -----
1 wwww A
1 ffff F
1 dddd P
1 ffff R
2 AAA I
2 AAA Z

I have written this query but it gives me the below output :

SELECT Name,Code FROM (SELECT ROW_NUMBER() OVER(PARTITION BY
Name,Code) AS rn, Name,Code FROM tablename ) AS T WHERE rn = 1 order BY
Name
Name Code
----------- -----
1 dddd P
1 ffff F
1 ffff R
1 wwww A
2 AAA I
2 AAA Z

I have tried all combintaions but still am not able to group by the
Code
If I got this right, then you _do not_ want to do any grouping, i.e. you
don't want to use GROUP BY. What you do want to have, however, is a
certain order of the result rows, correct?

SELECT name, code
FROM tablename
ORDER BY INTEGER(SUBSTR(name, 1, POSSTR(name, ' ') - 1)), code

I've been using just the first characters in your NAME column to extract the
number. We sort by this number and then by CODE.

p.s: Ideally, you would use a proper design and normalize your NAME column
into two separate columns.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 5 '06 #2
Hi Knut Stolze ,

thanks a lot !!! i wanted to group by and then do an Order by..

the table has been already designed and we are doing support for the
existing tables where in have to change the queries according to the
requirement...

will look into your Code and i used Locate earlier and now u have given
me another idea..

thanks !!!!
tariq

Dec 5 '06 #3
rAinDeEr wrote:
Hi Knut Stolze ,

thanks a lot !!! i wanted to group by and then do an Order by..
I'm wondering: What exactly are you grouping? Your query doesn't group
anything at all...

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Edwinah63 | last post by:
Hi Everyone, All the very best for 2004!! i need urgent help with this problem, the users are about to skin me alive!! we have an access front end with linked to sql server 2k tables. ...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
2
by: Dimitri | last post by:
PLEASE HELP,I HAVE A DATABSE WITH MULTIPLE RECORDS AS OUTLINED BELOW EMP NO LEVEL NEXTINCREASE WAGETYPE UNIT 1000 1 0 1000 1000 1 0 1002 ...
6
by: varkey.mathew | last post by:
Dear all, Bear with me, a poor newbie(atleast in AD).. I have to authenticate a user ID and password for a user as a valid Active Directory user or not. I have created the IsAuthenticated...
1
by: AVL | last post by:
Hi I'm working on indexing a website. I want to restict the search to only few file types like .doc,.txt and.ppt How to specify the file types in the 'ixsso.Query' object Presently i'n using...
6
by: sangram_149 | last post by:
hi, i have a query which fetches the sum of amounts from a table .the column is 19 bytes but the query returns only the actual amount..for example ..it returns ... -1245.00 but i want it to...
1
by: Liam.M | last post by:
HEY GUYS, need some urgent help here....I am querying my database based on a DueDate field...and want to send an automated email to anyone that falls within two months PRIOR to this "DueDate",...
2
by: JHNielson | last post by:
I Know I've posted an Urgent message before. But I'm in the middle of system testing, and these little stupid bugs are killing me...... I have a query that checks that a set of values (the...
5
by: gopim | last post by:
strSql = "SELECT ISNULL(max(substring(User_ID,2,len(User_ID))) + 1,'100') FROM Users"; sqlCmd.CommandText = strSql; sqlDr = sqlCmd.ExecuteReader(); ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.