如何忽略分组依据 SQL 列中不同数量的起始 0
我正在使用以下查询来查找表中的重复数字:
SELECT
c.code,
COUNT(c.code)
FROM cards c
group by c.code
HAVING COUNT(c.code)>1;
但是列代码在数字之前有不同数量的 0,例如:
0001897
001897
01897
1897
如何使该查询忽略数字之前的所有 0 以将上述所有内容视为重复(分组中的同一行)?
I am using the following query to find repeated numbers in my table:
SELECT
c.code,
COUNT(c.code)
FROM cards c
group by c.code
HAVING COUNT(c.code)>1;
But the column code has varying numbers of 0s before the numbers, as an example:
0001897
001897
01897
1897
How could I make that query ignore all 0s before the numbers to consider all of the above as repeated (the same row in a group by)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用 TRIM 函数
前导“0”
SQLFIDDLE
You can try to use TRIM function with
LEADING '0'
SQLFIDDLE