Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将值转换为SQL名称_Sql_Inner Join - Fatal编程技术网

将值转换为SQL名称

将值转换为SQL名称,sql,inner-join,Sql,Inner Join,我有两张桌子 我不想显示Currency1Id和Currency2Id,而是想显示currencyquirtcut,让它看起来更好 在任何情况下,我都只能加入如下字段之一: 请帮助我将两者转换为货币表的值 谢谢 我想你需要的是这样的东西 SELECT c1.CurrencyShortcut [Currency1], c2.CurrencyShortcut [Currency2] /*, other columns you need*/ FROM Spot as s JOI

我有两张桌子

我不想显示
Currency1Id
Currency2Id
,而是想显示
currencyquirtcut
,让它看起来更好

在任何情况下,我都只能加入如下字段之一:

请帮助我将两者转换为货币表的值


谢谢

我想你需要的是这样的东西

SELECT c1.CurrencyShortcut [Currency1], c2.CurrencyShortcut [Currency2] 
    /*, other columns you need*/
FROM Spot as s
    JOIN Currencies as c1 ON s.CurrencyId = c1.CurrencyId
    JOIN Currencies as c2 ON s.CurrencyId = c2.CurrencyId

您也可以为列设置别名

SELECT 
     c1.Currency1Id     AS Currency1Shortcut
     , c2.Currency2Id   AS Currency2Shortcut

你能解释一下你用的c1是什么吗,它是变量还是类似的东西?当我尝试这样做时,它会给我一个错误。你能再解释一点吗(对不起,我对SQL真的很陌生)@Light\u用户他们被称为表中的一员。SQL server不要求将
用作
关键字,但某些数据库需要这样做。它们用于减少键入完整表名的次数。@Light\u User您的数据库是什么,出现了什么错误?谢谢,我花了一段时间才找到:)效果很神奇:)当查看第二个表时,我想您不想使用单独的表,除非需要它们之间的关系