Re: Frequency distribution SQL statement
From: Steve (sedmyer_at_indy.rr.com)
Date: 02/04/05
- Next message: mvp: "RE: SQL XML"
- Previous message: Anith Sen: "Re: Cannot update identity column"
- In reply to: Dean: "Re: Frequency distribution SQL statement"
- Next in thread: Dean: "Re: Frequency distribution SQL statement"
- Reply: Dean: "Re: Frequency distribution SQL statement"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 04 Feb 2005 18:19:53 GMT
Dean,
This looks like what I need. Could you help me to write this as a stored
procedure that would take the min value (zero in your sample SQL), the max
value (30 in your sample SQL) and the increment (10 in your sample) as
parameters.
thank you much for your help
Steve
"Dean" <deanv@nospam.spin.hr> wrote in message
news:etW$SAuCFHA.2296@TK2MSFTNGP15.phx.gbl...
> something like this?
>
> SELECT range, COUNT(attrib_value) AS TOTAL
> FROM
> (SELECT
> CASE
> WHEN attrib_value BETWEEN 0 AND 10 THEN '0-10'
> WHEN attrib_value BETWEEN 10 AND 20 THEN '10-20'
> WHEN attrib_value BETWEEN 20 AND 30 THEN '20-30'
> ELSE 'else'
> END AS range,
> attrib_value
> FROM t
> WHERE attrib_name = 'Age') a
> GROUP BY range
> ORDER BY TOTAL DESC
>
> dean
>
> "Steve" <sedmyer@indy.rr.com> wrote in message
> news:jlNMd.5365$4x5.2854@fe2.columbus.rr.com...
>> OOPS, did not complete my response before sending. Let me try again.
>> Comments inline
>>
>> "David Gugick" <davidg-nospam@imceda.com> wrote in message
>> news:ufCrJPtCFHA.1408@TK2MSFTNGP10.phx.gbl...
>> > SELECT attrib_value, COUNT(attrib_value) AS TOTAL
>> > FROM MyTable
>> > WHERE attrib_name = 'Age'
>> > and (attrib_value >=20 and attrib_value <=25)
>>
>> This will work for the single range but what I need is to get many ranges
>> from a single SQL statement. So the result would indicate that age = 20
> to
>> 25 has a count of x, age = 25 to 30 has count of y, age = 30 to 35 has
>> count of z, etc. Further I would like the Max, Min and increment values
> (in
>> the previous example min = 20 max = 35 and increment = 5) to be
>> parameters
>> of the query. Hummm, as I say that it seems that what I really need here
> is
>> a stored procedure. If some one could help me with that it would be
> great.
>> I am a VB programmer and am not real sure as to how to go about coding
>> stored procedures
>>
>> > GROUP BY attrib_name -- shouldn't this be ATTRIB_NAME???
>>
>> I do not think so...the where clause will ensure that only the
>> attrib_name
>> 'Age' will be returned (no need to group by a single value) and the idea
> is
>> to group the results by the frequency of occurance of a specific age
>> value
>>
>>
>> >
>> >
>> > --
>> > David Gugick
>> > Imceda Software
>> > www.imceda.com
>>
>>
>
>
- Next message: mvp: "RE: SQL XML"
- Previous message: Anith Sen: "Re: Cannot update identity column"
- In reply to: Dean: "Re: Frequency distribution SQL statement"
- Next in thread: Dean: "Re: Frequency distribution SQL statement"
- Reply: Dean: "Re: Frequency distribution SQL statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|