Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 18,859 of 19,505    |
|    migurus to All    |
|    need help with ordering groups of record    |
|    17 Apr 13 18:21:02    |
      From: migurus@yahoo.com              I have a list of customers and addresses they have visited, each record has a       count of visits. I need to re-sort the list in such a way that customers with       higher counts will be higher on the list, but all his/her records should stay       together              To illustrate:       declare @T table ( ID int, NAME varchar(32), ADDR varchar(32), CNT int );       insert into @T values       (1001, 'JOHN DOE', '100 MAIN ST', 200),       (1001, 'JOHN DOE', '2040 1ST ST', 50),       (1001, 'JOHN DOE', '1 WESTIN ST', 220),       (1225, 'BOB GARE', '50 GREEN ST', 195),       (1405, 'JUAN SILVA', '50 GREEN ST', 225),       (1405, 'JUAN SILVA', '300 PALM DR', 25);              I need to get list ordered like below:       ID NAME ADDR CNT       1405 JUAN SILVA 50 GREEN ST 225       1405 JUAN SILVA 300 PALM DR 25       1001 JOHN DOE 100 MAIN ST 200       1001 JOHN DOE 2040 1ST ST 50       1001 JOHN DOE 1 WESTIN ST 220       1225 BOB GARE 50 GREEN ST 195              As you see, Juan Silva has 225 visits, which is highest of them all, so all       his records are sorted before everybody else. The order of records within       group belonging to the same customer is not important.              Any hint or idea would be appreciated.              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca