正确的 SQL 数据表查询编写
我有一个表 t1,其中包含三列 id、c1、c2、c3 和某些数字。我有一个不同的表 t2 ,其中 id,name 中的值是 c1,c2,c3 的值。
我无法编写一个查询来获取结果作为
id | c1 的名称 | c2 的名称 | c3 的名称
有人可以帮忙吗?
I have a table t1 with three columns id,c1,c2,c3 with certains numbers. I have a different table t2 with id,name where values in id are values of c1,c2,c3.
I am unable to write a query where i can get results as
id | names of c1 | names of c2 | names of c3
can somebody help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要对每个值连接三次才能获得它们的名称。
对于蹩脚的别名,我深表歉意。
You will need to join three times on each of the values to get their name.
I apologize for the crappy aliasing.
但是你应该修复你的数据模型,3 列具有相同类型的数据,听起来像是一个糟糕的数据模型。做一些标准化。
But you should fix your datamodel, 3 columns with the same type of data, sounds like a bad datamodel. Do some normalization.
一种方法是编写子查询来检索每列的名称:
或者您可以使用 Tripe 连接:
One way would be to write subqueries to retrieve the name for each column:
Or you could use a tripe join: