如果产品ID是连续的,我们需要获取行。
表格(产品)
product_id name
1 Parle
2 Coconut
3 Pizza
4 Colgate
5 Ice Cream
6 Nuts
8 Britania
9 Pepsi
需要输出的结果
product_id name
1 Parle
2 Coconut
3 Pizza
4 Colgate
5 Ice Cream
6 Nuts
product_id - 8和9
没有得到,因为它们不是按顺序排列的。
我的翻译
select distinct t1.*, t1.product_id, (select GROUP_CONCAT(t2.product_id) from product as t2) as p_id
from product t1
having FIND_IN_SET(t1.product_id+1, p_id)
输出
product_id name
1 Parle
2 Coconut
3 Pizza
4 Colgate
5 Ice Cream
在这个尝试中,我没有得到
product_id - 6
行。注:我想要的是
MySql
查询而不是PHP
。
谢谢!