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.
很难弄清楚应该如何编写它,我有一个由固定数字列和递增数字列组成的键。
我想让选择查询只返回每个固定数字的最新行。
例如:
20, 1 20, 2 20, 3 <-- Should only return these rows 25, 1 25, 2 <-- 30, 1 30, 2 30, 3 <--
是否可以在单个查询中编写此代码而无需遍历 php 中的结果?
尝试这个::
select max(column1), column2 from table group by column2
select col1, max(col2) from table group by col1
会给你
20 3 25 2 30 3
SqlFiddle 演示