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.
我有两个使用以下简单结构的表:
----------- id | count| -----------
一张男桌,一张女桌。我想比较两个表的行并选择计数最高的行。例如:
如果一行的计数为 500,而另一行的计数为 200,则应选择第一行,并将其与其余行的结果一起添加到新表中。
这假设 table_a 和 table_b 具有相同的 id:
INSERT INTO new_table (id, count) SELECT table_a.id, GREATEST(table_a.count, table_b.count) FROM table_a LEFT JOIN table_b ON table_a.id = table_b.id