java - SQLite Query - A short list of individual records which appear multiple times and ordered by the number of times they occur? -
say have table following records:
+----+-------+--------+ | id | type | item | +----+-------+--------+ | 1 | food | apple | | 2 | food | apple | | 3 | food | orange | | 4 | food | apple | | 5 | food | banana | | 6 | food | banana | | 7 | drink | cola | | 8 | drink | water | | 9 | food | banana | | 10 | food | apple | +----+-------+--------+ how construct query return single column list of items, of type:food, , contains 1 occurrence of each item appears multiple times in table - , ordered number of times appear in table?
so result above table following list:
-apple (4 occurrences) -banana (3 occurrences) -orange (1 occurrence) thanks.
try this:
select item, count(item) count tablename type='food' group item order count desc result:
item count apple 4 banana 3 orange 1 see result in sql fiddle.
Comments
Post a Comment