删除不带前导零的行
我有一个带有列的表(registration_no varchar(9))。这是一个示例:
id registration no
1 42400065
2 483877668
3 019000702
4 837478848
5 464657588
6 19000702
7 042400065
请注意注册号,例如(042400065)和(42400065),它们几乎相同,区别只是前导零。
我想选择与上面大小写相同的所有注册号,并删除没有前导零的注册号,即(42400065)
,另请注意,在删除没有前导零的注册号(42400065)之前,我需要确保有等价于前导零 (042400065)
I have a table with a column (registration_no varchar(9)). Here is a sample:
id registration no
1 42400065
2 483877668
3 019000702
4 837478848
5 464657588
6 19000702
7 042400065
Please take note of registration numbers like (042400065) and (42400065), they are almost the same, the difference is just the leading zero.
I want to select all registration numbers that have the same case as above and delete the ones without a leading zero i.e (42400065)
pls, also note that before i delete the ones without leading zeros (42400065), i need to be sure that there is an equivalent with leading zeros(042400065)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您可以使用单个 DELETE 语句来完成此操作。 JOIN 确保只有重复项才能被删除,并且约束通过不以“0”开头的注册号进一步限制它。
运行上述 DELETE 后,您的表看起来像这样。我在 SQL Server 2008 实例上测试了它。
I think you can do this with a single DELETE statement. The JOIN ensures that only duplicates can get deleted, and the constraint limits it further by the registration numbers that don't start with a '0'.
Your table looks like this after running the above DELETE. I tested it on a SQL Server 2008 instance.
该解决方案不依赖于特定长度的注册号,它只是查找具有相同整数但不相同值(因为前导零)的注册号,并选择具有“0”的条目作为第一个字符。
This solution won't depend on the registration numbers being a particular length, it just looks for the ones that are the same integer, yet not the same value (because of the leading zeroes) and selects for the entry that has a '0' as the first character.