Peng Yu <pengyu...@...> writes: > > Hi, > > SELECT DISTINCT type_id FROM foods; > > If I use 'distinct', any entry that shows up greater or equal to one > time will only appear once. But I want to select an entry that appears > <=n times and only show n times if it appears more than n times. I > think that "group by" might help. But I'm not familiar with SQL enough > yet. Would you please let me know what command to use? >
what about SELECT entry, CASE WHEN cnt <= n THEN cnt ELSE n END AS result FROM ( SELECT entry, COUNT(entry) as cnt FROM table GROUP BY entry ) ; Oliver _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users