|
Posted by Erland Sommarskog on 09/30/66 11:16
(chudson007@hotmail.com) writes:
> That seems to just count the number of times each qty appears, just
> like
>
> SELECT qty AS Expr1, COUNT(*) AS Expr2
> FROM [Temp]
> GROUP BY qty
>
>
> How should I change it so that it counts the the number of qtys between
> each range of 10?
The query I posted was:
SELECT qty10, COUNT(*)
FROM (SELECT qty10 = ((qty - 1) / 10) * 10 + 1
FROM tbl) AS ds
GROUP BY qty10
I would expect to give the desired result, assuming that qty is integer.
If qty is float or decimal, it will indeed just be a roundabout way to
count single qtys.
I will have to admit that I did not test my query, but there is standard
recommendation that posting asking for help with queries should include:
o CREATE TABLE statement for your table(s).
o INSERT statement with sample data.
o The desired output given the sample data.
This makes it very easy for me or anyone else who anser to cut and paste
into Query Analyzer and test whatever we post.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Navigation:
[Reply to this message]
|