MySQL 行优先级

发布于 2024-07-12 13:23:22 字数 522 浏览 3 评论 0原文

我有一个数据库表,里面充满了一些非常丑陋和混乱的数据。 在一个单独的表中,我有一个更干净的数据版本,它们通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糯酥胸 2024-07-19 13:23:22
SELECT IFNULL(cleandata, uglydata)
FROM uglytable
LEFT OUTER JOIN cleantable
ON clean_id = ugly_id
SELECT IFNULL(cleandata, uglydata)
FROM uglytable
LEFT OUTER JOIN cleantable
ON clean_id = ugly_id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文