我如何使用 SQL 来编写这个?
我需要在sql中编写一段代码,当存在重复的Id_numbers(例如:234566)但Phone_number中的一个值以A开头而另一个值以B开头时,在“Adjustment_name”列中写入“del_row”在这种情况下,它将在“Phone_number”列中的值以“B”开头的行中写入“del_row”。想象一下,我有两个重复的 id_numbers,其中一个的 Phone_number 以 A 开头,另一行以“C”开头。在最后的情况下,我不想写任何东西。
Id_number | Phone_number | adjustment_name |
---|---|---|
234566 | A5258528564 | |
675467 | A1147887422 | |
675534 | P1554515315 | |
234566 | B4141415882 | del_row |
234566 | C5346656665 |
非常感谢!
I need to write a code in sql that writes "del_row" in the column "Adjustment_name" when there are duplicated Id_numbers (e.g:234566) but just when one of the values in Phone_number start with A and other one start with B and in that case, it will write "del_row" just in the row in which the value in column "Phone_number" starts with "B". Imagine that I have two duplicated id_numbers and in one of them, the Phone_number starts with A and in the other row starts with "C". In this last situation, I don't want to write anything.
Id_number | Phone_number | Adjustment_name |
---|---|---|
234566 | A5258528564 | |
675467 | A1147887422 | |
675534 | P1554515315 | |
234566 | B4141415882 | del_row |
234566 | C5346656665 |
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法
One approach
一个相当粗略的方法如下
(假设您的手机排名为 Axxx、Bxxx、Cxxx、Dxxx)。如果您的电话编号逻辑不同 - 这与您的要求不太清楚 - 您可以进行相应调整。
A rather crude approach would be as below
(assuming your phones rank Axxx, Bxxx, Cxxx, Dxxx). If your phone numbering logic is different - which is not very clear from your req - you can adjust accordingly.