2016-08-11 2:29 GMT+02:00 R Smith <[email protected]>: > WITH TC(Tot) AS ( > SELECT CAST(COUNT(*) AS REAL) FROM T > ) > SELECT Grp, (COUNT(*) / Tot * 100) AS Perc > FROM T, TC > GROUP BY Grp; > > > -- Grp | Perc > -- ------------ | -------------------- > -- 1 | 15.3846153846154 > -- 2 | 23.0769230769231 > -- 3 | 7.69230769230769 > -- 4 | 46.1538461538462 > -- 5 | 7.69230769230769 > > WITH TC(Tot) AS ( > SELECT CAST(COUNT(*) AS REAL) FROM T > ), SL(Slice) AS ( > SELECT CAST(((100 * COUNT(*) / Tot) / 5) AS INT) * 5 > FROM T, TC > GROUP BY Grp > ), ST(SliceTot) AS ( > SELECT CAST(COUNT(*) AS REAL) FROM SL > ) > SELECT Slice, COUNT(*), (COUNT(*) / SliceTot * 100) AS Perc > FROM SL, ST > GROUP BY Slice > > > -- Slice | COUNT(*) | Perc > -- ------------ | -------- | ------ > -- 5 | 2 | 40.0 > -- 15 | 1 | 20.0 > -- 20 | 1 | 20.0 > -- 45 | 1 | 20.0
This does something completely different. It takes the percentages rounded down to 5 and shows how often they occur. 7.69 -> 5 (twice) 15.38 -> 15 23.07 -> 20 46.15 -> 45 The values I look at can only be between 0 and 100, so I want the percentage of values that are >= 0 AND <= 10 >= 11 AND <= 20 … -- Cecil Westerhof _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

