home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / sybase / 587 < prev    next >
Encoding:
Text File  |  1993-01-04  |  2.4 KB  |  64 lines

  1. Newsgroups: comp.databases.sybase
  2. Path: sparky!uunet!psinntp!ctp!sreit
  3. From: sreit@ctp.com (Stefan Reitshamer)
  4. Subject: SQL sort problems (group by?)
  5. Message-ID: <1993Jan4.193801.25423@ctp.com>
  6. Sender: news@ctp.com
  7. Nntp-Posting-Host: punch.ctp.com
  8. Organization: Cambridge Technology Partners
  9. Date: Mon, 4 Jan 1993 19:38:01 GMT
  10. Lines: 52
  11.  
  12. I need to sort data in a bizarre way and have NO idea how to do it (other
  13. than looping through rows and assigning index numbers and then selecting
  14. by ascending index number). Here's the data involved:
  15.  
  16. Claim #  Subscriber #  Date
  17. -------  ------------  --------
  18. 22402    111111111     10/10/92
  19. 55600    333333333     04/04/92
  20. 45200    222222222     09/15/92
  21. 22404    111111111     08/08/92
  22. 22400    111111111     09/09/92
  23. 44900    111111111     08/30/92
  24. 45202    222222222     07/01/92
  25.  
  26. The last 2 digits of the claim # are adjustment numbers (the 00 claim is the
  27. original, others are adjustments of the original).
  28. I need to sort this data by subscriber number, and by descending date 
  29. within each sub #. BUT, if a claim has been adjusted, I need the adjusted 
  30. claims to appear after the original (regardless of the date).
  31.  
  32. Basically, rows with the first 3 digits of the claim # in common should be
  33. grouped together. These groups should then be sorted by sub # and descending
  34. date.
  35.  
  36. So, the above data would be sorted as follows:
  37.  
  38. Claim #  Subscriber #  Date
  39. -------  ------------  --------
  40. 44900    111111111     05/05/92                     ]Group 1
  41. 22400    111111111     02/02/92                          ]Group 2
  42. 22402    111111111     03/03/92 <- Adjustment of 22400   ]Group 2
  43. 22404    111111111     08/08/92 <- Adjustment of 22400   ]Group 2
  44. 45200    222222222     01/01/92                   ]Group 3
  45. 45202    222222222     07/01/92                   ]Group 3
  46. 55600    333333333     04/04/92              ]Group 4
  47.  
  48. I was thinking something like:
  49.     select *
  50.     group by round(Claim#/100,0)
  51.     order by Subscriber,Date desc
  52. but I guess this is incorrect usage of the "group by" clause.
  53.  
  54. Does anyone know how to "select" this? (Hope this explanation makes some sort
  55. of sense)
  56.  
  57. Thanks very much!
  58.   Stefan
  59. -- 
  60. ``````````````````````````````````````````````````````````````````````````````
  61. Stefan Reitshamer      sreit@ctp.com       Cambridge Technology Partners, Inc.
  62.      Opinions expressed herein belong to no one at all (just to be safe).
  63. ``````````````````````````````````````````````````````````````````````````````
  64.