讓我們重新創建測試用例:
sqlite> create table vegetables(id int, value text);
sqlite> insert into vegetables values('1', 'Banana');
sqlite> insert into vegetables values('2', 'Carrot');
sqlite> insert into vegetables values('3', 'Apple');
sqlite> insert into vegetables values('4', 'Apple');
sqlite> insert into vegetables values('5', 'Banana');
sqlite> insert into vegetables values('6', 'Apple');
sqlite> insert into vegetables values('7', 'Apple');
sqlite> insert into vegetables values('8', 'Banana');
sqlite> insert into vegetables values('9', 'Apple');
檢查的數據是一樣的你:
sqlite> select * from vegetables;
1|Banana
2|Carrot
3|Apple
4|Apple
5|Banana
6|Apple
7|Apple
8|Banana
9|Apple
如果你想用最少的出現蔬菜:
sqlite> select value from vegetables group by value order by count(value) limit 1;
Carrot
如果你想要的蔬菜出現次數最多:
sqlite> select value from vegetables group by value order by count(value) desc limit 1;
Apple
請試試看。謝謝 –