Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming id is a key column, try this:</p> <pre><code>Select Case When money &lt; 100 Then 'LT100' When money &lt; 200 Then 'From100To199' When money &lt; 300 Then 'From200To299' When money &lt; 1000 Then 'From300To999' Else 'GE1000' End Bucket, Count(*) Count From Table Group By Case When money &lt; 100 Then 'LT100' When money &lt; 200 Then 'From100To199' When money &lt; 300 Then 'From200To299' When money &lt; 1000 Then 'From300To999' Else 'GE1000' End </code></pre> <p>EDIT: If the length or size of the buckets is a constant, (or can be represented as a SQL Expression) then you can do any arbitrary number of buckets by defining the buckets as the output of that expression, as in, for example, to defined every $100 dollar buckets:</p> <pre><code>Select Str(Floor(Cast(money / 100)), 8, 0) Bucket, Count(*) Count From Table Group By Str(Floor(Cast(money / 100)), 8, 0) </code></pre> <p>or, to have 100 dollar buckets up to $1000, and then $1000 buckets from there on up:</p> <pre><code>Select Case When Money &lt; 1000 Then Str(Floor(Cast(money / 100)), 8, 0) Else Str(Floor(Cast(money / 1000)), 8, 0) End Bucket, Count(*) Count From Table Group By Case When Money &lt; 1000 Then Str(Floor(Cast(money / 100)), 8, 0) Else Str(Floor(Cast(money / 1000)), 8, 0) End </code></pre> <p>to get accumulated counts, I'd use the output of above SQL querys as a subquery in another SQL: Using the first one as example:</p> <pre><code> Select LT100, LT100 + From100To199 LT200, LT100 + From100To199 + From200To299 LT300, LT100 + From100To199 + From200To299 + From300To999 LT1000, LT100 + From100To199 + From200To299 + From300To999 + GE1000 Total From ( Select Case When money &lt; 100 Then 'LT100' When money &lt; 200 Then 'From100To199' When money &lt; 300 Then 'From200To299' When money &lt; 1000 Then 'From300To999' Else 'GE1000' End Bucket, Count(*) Count From Table Group By Case When money &lt; 100 Then 'LT100' When money &lt; 200 Then 'From100To199' When money &lt; 300 Then 'From200To299' When money &lt; 1000 Then 'From300To999' Else 'GE1000' End) Z </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload