0

我不知道它叫什么,所以我将尝试解释一下。

假设有两个表,tableA并且tableB.

  • 其中tableA有一列有一个数字(例如105)
  • tableB其中有一列有文本(例如'This')

105 的意思是“这个”。

所以一个数字存储在A表中 w/c 在表中是有意义的B

我想得到这个tableA号码,但是当它显示出来时,它会显示“这个”。

逻辑:如果 A 的结果为 105,则显示来自 B 的等效文本,其中 id 为 105。显示:THIS

SELECT TOP 1
    CHAR_KEY AS charid,
    USER_KEY AS userid,
    CONVERT(VARCHAR,substring(char_data, 9, 16)) AS name,
    CONVERT(INT,cast(reverse(substring(char_data, 7, 2)) as BINARY(2))) AS level,
    CONVERT(INT,substring(char_data, 25, 1)) AS type,
    CONVERT(INT,cast(reverse(substring(char_data, 263, 2)) as BINARY(2))) AS strength,
    CONVERT(INT,cast(reverse(substring(char_data, 265, 2)) as BINARY(2))) AS wisdom,
    CONVERT(INT,cast(reverse(substring(char_data, 267, 2)) as BINARY(2))) AS dexterity,
    CONVERT(INT,cast(reverse(substring(char_data, 269, 2)) as BINARY(2))) AS charisma,
    CONVERT(INT,cast(reverse(substring(char_data, 271, 2)) as BINARY(2))) AS intelligence,
    CONVERT(INT,cast(reverse(substring(char_data, 273, 2)) as BINARY(2))) AS constitution,
    CONVERT(INT,cast(reverse(substring(char_data, 309, 4)) as BINARY(4))) AS fame,
    CONVERT(INT,cast(reverse(substring(char_data, 33, 4)) as BINARY(4))) AS guild,
    CONVERT(INT, substring(char_data, 261, 1)) AS permission
FROM CHAR_DATA0 WHERE CONVERT(INT, substring(char_data, 261, 1))=0x00 ORDER BY level DESC

获取公会名称的查询。

SELECT 
    guild_name
FROM guild_data WHERE guild_key=guild

我想要得到的是guild.

示例来自第一个 SELECT 查询guild结果:518

在表 guild_data 上,一列 guild_name 包含公会 518 的名称。518 是 guild_key。

请帮忙,谢谢。

4

2 回答 2

1
SELECT
    guild_data.guild_name
FROM CHAR_DATA0
inner join guild_data on guild_key = CONVERT(INT,cast(reverse(substring(char_data, 33, 4)) as BINARY(4)))
WHERE CONVERT(INT, substring(char_data, 261, 1))=0x00 ORDER BY level DESC
于 2012-07-22T21:08:05.833 回答
0

你需要一个“选择”和一个“加入”

  select b.text
  from tablea a 
  inner join tableb b on a.id = b.id
  where a.id = 105

但是,要使这项工作正常进行,您需要在两个表中都有“id”。

于 2012-07-22T21:09:27.260 回答