问题:我需要通过电话统计不在table2
中的行,我有两个表
描述:table1
有phone列,table2
也有phone
列。
问题是,有时 phone
列可能包含“-”,我想将其删除,以便比较和计数它是否不存在于 table1
中。示例:
table1 table2
id phone id phone
1 01-123 1 01123
2 12345 2 23456
预期结果计数需要为 1 。 到目前为止,我写了这个查询,但它不起作用,有什么帮助吗?
SELECT count(*) FROM table1 WHERE NOT EXISTS (SELECT * FROM table2 WHERE REPLACE(table1.phone, '-', '') = REPLACE(table2.telephone, '-', ''))
最佳答案
你必须尝试 NOT IN
SELECT Count(*)
FROM table1
WHERE phone NOT IN (SELECT Replace(telephone, '-', '')
FROM table2);
关于mysql - 在没有 '-' mysql 的情况下计算不在另一个表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30568415/