June 20, 2005 at 10:07 am
Hi all,
I have a table like this below
OrderID Step Type
12 10 1,2,3,4
12 20 2,3
12 30 1,2,4
so, I need to get the Max no. of type, when I supply the orderID.
When I give OrderID = 12, then the query should display the type 2.
give me some idea how can i get that. thanks
June 20, 2005 at 10:18 am
You design is flawed. The type colum should be placed into its own table like so :
Table orderTypes
orderid, step, Type (all this being your clustered primary key)).
Then do this :
Select top 1 /*with ties*/ type, count(*) from dbo.OrdersTypes
where orderid = 12
group by type
order by Count(*) desc
June 20, 2005 at 10:28 am
I agree - having your db designed like this will always frustrate you as queries which should take 30 seconds to write will take 30 minutes and perform 10 times worse. Can you modify the db design?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
June 20, 2005 at 10:46 am
Thnks, I'm gng to do tht. I had it in my mind but I didn't have proper privillages to change it
June 21, 2005 at 1:43 am
Thnks, I'm gng to do tht. I had it in my mind but I didn't have proper privillages to change it
If you don't have this privileges, but there is the chance to change it, ask someone else to change it. You might also want to tell that person, that such a design violates First Normal Form.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply