Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL breakdown of data
Message
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01648857
Message ID:
01648860
Vues:
86
>>>Hello,
>>>
>>>I have a table with 1,500 records and with one column: ID, comprised of numeric data ranging from 1 - 1,591. As the
>>>numbers get higher, the frequency of their appearance increases. But what's important, is not so much any given value
>>>but how many numbers appear within a given range. And yes, I am trying to figure out a cutoff point that will separate
>>>this table into the numbers that appear with the highest frequency (they happen to be larger numbers, in this table)
>>>and numbers that appear less frequently (they happen to be smaller numbers.)
>>>So, I want to know if certain values appear more often than others, kind of like a heat map, except the response would
>>>be in a tabular form rather than in graphic.. Is there a way to use an SQL statement to do this? Can I preselect
>>>the number of ranges and their size, for example: break the table up into 20 ranges. But I can't know
>>>which values each of the 20 ranges will have in advance? I know it's a vague question but I wondered
>>>what you all might say as this kind of question is coming up a lot.
>>>
>>>Thank you,
>>>Steve
>>
>>Hi, Steve,
>>
>>Can you post the table structure (at least for the relevant columns)?
>
>table name: MY_IDS
>field name: ID
>data type: numeric
>range of values in ID: 1 - 1,591
>number of rows: 1,500
>
>(I tried to upload the dbf but the system won't allow it.)

Try
;with counts as (select Id, count(Id) as frequency
from My_IDS
group by Id)

select *, NTILE(5) OVER (order by Frequency)
from counts -- group into 5 different buckets in order of the frequency
The above is for SQL Server.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform