home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / database / 8508 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  2.1 KB

  1. Path: sparky!uunet!gossip.pyramid.com!pyramid!unify!atlantis!meh
  2. From: meh@atlantis.Unify.Com (Mark E. Hansen)
  3. Newsgroups: comp.databases
  4. Subject: Re: Interative SQL Query Question
  5. Message-ID: <gppb1p7@Unify.Com>
  6. Date: 15 Dec 92 20:26:28 GMT
  7. References: <lhv4hlINN9ne@jethro.Corp.Sun.COM> <1992Dec5.195857.1775@uunet!cbmvax!xmws!kripalu>
  8. Sender: meh@atlantis (Mark E. Hansen)
  9. Organization: Unify Corporation, Sacramento, CA, USA
  10. Lines: 66
  11.  
  12. In article <1992Dec5.195857.1775@uunet!cbmvax!xmws!kripalu>, harit@kripalu.com writes:
  13. |> In article <lhv4hlINN9ne@jethro.Corp.Sun.COM> pmccurdy@alcalde.Corp.Sun.COM  
  14. |> (Patrick McCurdy) writes:
  15. |> > 
  16. |> > Hi All,
  17. |> > 
  18. |> >    I have been struggling with this one for quite some time, and I
  19. |> > just can't seem to get it right.
  20. |> > 
  21. |> >    My table has a column called requestor.  Now, it is a simple
  22. |> > matter to find out how many of the rows were requested by any
  23. |> > specific requestor with:
  24. |> > 
  25. |> > 
  26. |> >     select count(*)
  27. |> >     from TableName
  28. |> >     where Requestor = 'name'
  29. |> > 
  30. |> > 
  31. |> >    But what if I want to select the count for EACH distinct
  32. |> > requestor?   I have tried:
  33. |> > 
  34. |> > 
  35. |> >     declare @REQ varchar(25)
  36. |> >     while (select @REQ = (distinct(Requestor)))
  37. |> >     begin
  38. |> >         select count(*) 
  39. |> >         from HRISPerm
  40. |> >         where Requestor = @REQ
  41. |> >     end
  42. |> > 
  43. |> > 
  44. |> > but this does not work.  Any help on this question would be greatly
  45. |> > appreciated.
  46. |> > 
  47. |> > 
  48. |> > Patrick McCurdy
  49. |> > Systems Support Specialist
  50. |> > Sun Micro
  51. |> 
  52. |> try something like this:
  53. |> 
  54. |> select count(*) from HRISPerm group by Requestor
  55.  
  56. I'm sure you meant:
  57.     
  58.     select count(*), Requestor from HRISPerm group by Requestor
  59.  
  60. The count by itself wouldn't be very useful.
  61.  
  62.  
  63. |> 
  64. |> 
  65. |> -- 
  66. |> Michael Allen Latta
  67. |> Kripalu Center
  68. |> harit@kripalu.com
  69. |> (413)448-3288
  70.  
  71. -- 
  72. Mark E. Hansen                                     internet: meh@Unify.Com
  73. Unify Corporation                           ...!{csusac,pyramid}!unify!meh
  74. 3901 Lennane Drive                                   voice: (916) 928-6234
  75. Sacramento, CA 95834-1922                              fax: (916) 928-6401
  76.  
  77.           ** If there is no solution, there is no problem **
  78.