【发布时间】:2017-02-13 04:50:24
【问题描述】:
我有一个产品表和一个单独的表,其中列出了这些产品的各种翻译。基本设置如下所示:
dbo.Products
ProductID | Description
1 | An amazing product
2 | An even more amazing product
3 | Don't buy this one
dbo.ProductTranslations
ProductID | Language | Description
1 | EN-US | null
1 | FR-CA | Un produit étonnant
2 | EN-US | null
2 | FR-CA | Un produit encore plus étonnant
3 | EN-US | null
3 | FR-CA | Ne pas acheter celui-ci
我想做的基本上是将其展平,以便所有产品和翻译都在一个表中,并为每个产品压缩成一行,如下所示:
dbo.FlattenedProducts
ProductID | EN-US_Description | FR-CA_Description
1 | An amazing product | Un produit étonnant
2 | An even more amazing product | Un produit encore plus étonnant
3 | Don't buy this one | Ne pas acheter celui-ci
我已经挖掘了诸如 this one 和 this one 这样的示例,其中最好的建议(性能方面)似乎是使用大量案例陈述,但我正在努力将它们应用于我的情况。使用第二个链接中的 case 语句可以使翻译成为线性的,但它不会减少项目的总数。我正在处理 4000 万行(最终有十几个连接),因此速度至关重要,使用与所有这些数据不同的选择只会降低性能,我需要从选择语句中对数据进行清理。
我错过了什么技巧吗?
编辑:我应该注意,有时在翻译后的描述中存在真正的价值,当它是“EN-US”时(不要问为什么,我没有设计这个),而那些需要覆盖原始描述,所以我不能只是SELECT WHERE Language != 'EN-US' 或类似的。还有更多的语言不仅仅是英语和法语,我只是为了演示目的而对其进行了简化。
【问题讨论】:
标签: sql-server join pivot