我有两个mysql表
main_date_family
main_date_non_family
我想计算两个表中的重复记录,比如
---------------------
| id_file | c |
---------------------
| 1 | 3 |
| 6 | 2 |
| 14 | 5 |
答案 0 :(得分:2)
您需要使用SELECT
t.id_file,
COUNT(*) AS c
FROM
(
SELECT id_file FROM main_date_family
UNION ALL
SELECT id_file FROM main_date_non_family
) AS t
GROUP BY t.id_file
来实现输出:
SELECT
t.id,
COUNT(t.id) AS c
FROM
(
SELECT id_file AS id FROM main_date_family
UNION ALL
SELECT id_file FROM main_date_non_family
) AS t
WHERE t.id IN ( SELECT A.id_file
FROM main_date_family A
INNER JOIN main_date_non_family B ON A.id_file = B.id_file
)
GROUP BY t.id
修改强>
id_file
解释这个想法:
id_file
s。id_file
。请注意这一点
这个组合将这两个表中的所有id_file
都保存为
虽然它只是一张桌子。GROUP BY
个
第一步。COUNT
& group by
。 我猜
你知道什么是#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif