Table 1
ID Customer Tracking
--------------------
1 Nick 434
2 Jhon 437
3 Nick 456
4 Mike 544
Table 2
B_ID Customer Process
----------------------
1 Nick Payment
2 Tom Payment
3 Nick Payment
4 Mike Payment
5 Nick Payment
Echo
Table 1 Table 2
------------------
Nick 2 Nick 3
Mike 1 Mike 1
如何仅从两个不同的表和计数行中选择相似的值。
如您所见,表1中有2个Nick,表2中有3个Nick。
所以我只想从两个表中显示相似的客户。
最佳答案
您可以count
每个表(按名称分组)并加入结果:
SELECT customer1, cnt1, customer2, cnt2
FROM (SELECT customer AS customer1, COUNT(*) AS cnt1
FROM table1
GROUP BY customer) t1
JOIN (SELECT customer AS customer2, COUNT(*) AS cnt2
FROM table2
GROUP BY customer) t2 ON customer1 = customer2
关于php - 两个MYSQL表比较唯一行数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31082339/