ruud ruud - 7 months ago 12
SQL Question

How to write sql query to get items from range

I would like to get values without the smallest and the biggest ones, so without entry with 2 and 29 in column NumberOfRepeating.



My query is:

SELECT Note, COUNT(*) as 'NumberOfRepeating'
WHERE COUNT(*) <> MAX(COUNT(*))AND COUNT(*) <> MIN(COUNT(*))
FROM Note GROUP BY Note;

Answer
   SELECT Note, COUNT(*) as 'NumberOfRepeating'
FROM Notes

GROUP BY Note
HAVING count(*) < 
(

SELECT max(t.maxi)
FROM (select
Note, COUNT(Note) maxi FROM Notes
 GROUP BY Note
 ) as t 
)

 AND
 count(*) >
(

SELECT min(t.min)
FROM (select
Note, COUNT(Note) min FROM Notes
 GROUP BY Note
 ) as t 
)

try this code.