MySQL 行优先级
我有一个数据库表,里面充满了一些非常丑陋和混乱的数据。 在一个单独的表中,我有一个更干净的数据版本,它们通过 id 链接,但我需要保留混乱的数据集,并且在使用它检查数据差异时不能覆盖它。
我正在尝试将数据合并到一个新表中,或者在两个表中使用单个查询,并在结果中优先考虑干净的表结果。
因此,如果 id=3
uglydata=x7z
cleandata=xyz
,那么我会得到干净的数据,如果 cleandata
> 为空,我会得到丑陋的数据。 我尝试选择 cleandata
AS uglydata
,希望 MySQL 会覆盖其他字段,但这不起作用(是的,这很奇怪,我认为这不会工作)。
他们是这样做的好方法吗?
我能想到的另一个解决方案是首先从干净的数据插入新表,然后从丑陋的数据插入,因为出价是唯一的。
但我希望我能够按类型或其他方式对结果进行优先级排序。
I have a database table full of some really ugly and messy data. In a separate table, I have a cleaner version of the data and they are linked by an id, but I need to keep the messy dataset and can't overwrite it as I use it to check against data differences.
I'm trying to merge the data into a new table, OR use a single query across both tables and give the clean table results priority in the result.
So if id=3
uglydata=x7z
cleandata=xyz
, then I'd get the clean data, if cleandata
was null, I'd get the ugly data.
I tried selecting cleandata
AS uglydata
, hoping that MySQL would just overwrite the other field, but that doesn't work (and yes, it's weird and I figured that wouldn't work).
Is their a nice way to do this?
The other solution I can think if is just to insert into the new table from the clean data first, and then insert from the ugly data as the bid is unique.
But I'm hoping I'll be able to prioritize results by type or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)