Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
receipt_id order_id 1 A 2 B 3 B 4 C 5 C
显示该表中order_id计数大于1的所有记录的sql代码是什么?
你只需要一个聚合函数GROUP BY
GROUP BY
select order_id from yourtable group by order_id having count(order_id) > 1
请参阅带有演示的 SQL Fiddle
试试这个:
Select * from table where order_id in (select distinct order_id from table group by order_id having count(order_id) > 1)
演示