样本表数据
id id_order name phone price
1 4E0 A 789 $100
2 4E0 A 789 $100
3 4LK A 789 $200
4 2LP B 420 $50
5 DK2 B 420 $80
我希望结果像不同的行(id_order),其中phone =“ 789”
id id_order name phone price
1 4E0 A 789 $100
3 4LK A 789 $200
要么
id id_order name phone price
2 4E0 A 789 $100
3 4LK A 789 $200
我尝试了这个,但是没有得到想要的输出:
SELECT DISTINCT (id_order), * from table_name WHERE phone= "789";
最佳答案
select
min(id) id,
id_order,
name,
phone,
price
from yourtable
group by id_order, name, phone, price