我有一个如下的mysql表。我想计算浆果和草莓之间有多少行,在我的例子中是这两种水果之间有2行。我该如何实现?
id fruit
1 apple
2 berry
3 banana
4 pineapple
5 strawberry
最佳答案
试试这个查询
$sql = "SELECT COUNT(*) as total_count FROM table_name JOIN ( SELECT MAX(id) as
maxid,MIN(id) as minid FROM `table_name` WHERE fruit = 'berry' OR
fruit= 'strawberry') as temp ON table_name.id > temp.minid AND
table_name.id<temp.maxid";
关于php - 那有可能计算出两行mysql之间有多少行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34868793/