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.
如何在 MySQL 中的两个数据库表的列中返回重复值的计数?假设第 1 列的一行包含值“a”,第 2 列的行包含值“b”,类似地,第 1 列的另一行包含值“a”,第 2 列的行包含值“b”,那么我希望将计数返回为2. over partition by 不工作。
您是否尝试进行简单的聚合?
select col1, col2, count(*) from t group by col1, col2;
或者您是否尝试将此值附加到每一行:
select t.*, tsum.cnt from t join (select col1, col2, count(*) as cnt from t group by col1, col2 ) tsum on tsum.col1 = t.col1 and tsum.col2 = t.col2;