如何使用连接获得正确的值
这让我抓狂,我确信它相当简单,但无法正确执行。
有一个表保存不同年份的费率值:
Ratevaluetable
Year Value A Value B Value C
2009 10 15 20
2010 12 18 22
2011 14 21 25
然后我有另一个人员表:
User Time Price
john 2010 value B
Tina 2009 Value C
Bill 2011 Value C
现在我需要的是连接这两个表,以便我将 Price
列中的值替换为 中的数据>费率值表
。
我可以按时加入,但我不知道如何加入 Value
字段?
This is driving me nuts, I'm sure it's rather simple but can't get it right.
Having a table holding ratevalues for different years:
Ratevaluetable
Year Value A Value B Value C
2009 10 15 20
2010 12 18 22
2011 14 21 25
Then I have another persontable:
User Time Price
john 2010 value B
Tina 2009 Value C
Bill 2011 Value C
Now what I need is to join the 2 tables so that I get the value in the Price
column substituted with the data from the Ratevaluetable
.
I can join on time on year, but the I don't know how to join to the Value
fields?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于您当前的数据库架构来说这是不可能的。 Joins 通过匹配列值连接表;您建议在这里做的是将列值与列名称相匹配,这是不可能的。
可能的情况是:
给定上述架构,您可以以明显的方式将
User
连接到RateValueTable
。This is not possible with your current database schema. Joins connect tables by matching column values; what you propose to do here is match a column value with a column name, which is impossible.
What would be possible is:
Given the above schema, you could join
User
toRateValueTable
in the obvious manner.这是可能的,但这并不是最好的数据库设计。您必须执行条件语句来确定要获取 Ratevaluetable 的哪一列。
It is possible, but it's not really the best database design. You'd have to do a conditional statement to figure out which column of Ratevaluetable to get.