用 Max 删除
这是基于我的上一个问题。
我有下表
Table1
JobPositionId | JobPositionName
1 | Sound
2 | Lights
3 | Sound
4 | Ground
如何删除第三行(名称 = 声音和最大位置)
This is based on my previous question.
I have the following table
Table1
JobPositionId | JobPositionName
1 | Sound
2 | Lights
3 | Sound
4 | Ground
How can I delete row three (Name = sound, and max position)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用:
正如我在上一个问题中提到的,使用它不会触发 MySQL 1093 错误:
Use:
As I mentioned in your previous question, using this won't trigger a MySQL 1093 error:
抱歉,如果这没有考虑到您的“上一个问题”,我想我只想看看这个。
Sorry if this doesn't take into account your "previous question" thought I'd just look at this one.
看起来您想要做的是删除所有重复的 JobPositionNames,只留下 JobPositionId 最低的那个。
我最近不得不做一些非常类似的事情,发现 SQL 语句变得如此复杂,用 SQL 来做要容易得多(虽然效率低得多)。
因此,如果您要尝试清理这是一个被污染的数据库,只需编写一个脚本来完成此操作并完成它(并设置一些唯一索引以防止它再次发生)。
如果这种情况一直发生,并且需要定期完成,请修复执行此操作的代码。
It seems like what you are trying to do is to delete all duplicate JobPositionNames, leaving only the one with the lowest JobPositionId.
I had to do something very similar recently and found the SQL statements getting so complicated, it was much much easier (if much less efficient) to do it in SQL.
So in case this is a poluted database you're trying to clean, just write a script that does this and be done with it (and set some unique indexes to prevent it from happening again).
If this happens all the time, and needs to be done periodicaly, fix the code that does this.