我遇到了SQL查询(对于SQL Server)。我是SQL新手,我没有取得多大进展。我已经创建了一个测试标记的测试项目。
我有3张表如下:
Monster:
Name Description EatsPeople
Vampire Pale, afraid of light True
Ghost See-through, annoying False
Wraith Green-ish, ugly, dumb True
TagLookup:
Name ID
Ghost 1
Ghost 2
Wraith 1
Tags:
ID Text Value
1 Green green-skin
2 Screams like a banshee banshee-call
我正在尝试选择标记值为'green-skin'的所有怪物。
答案 0 :(得分:2)
假设Monsters.Name
中的Tags.Value
,Name-ID
和TagLookup
组合都是唯一的:
SELECT m.Name, m.Description, m.EatsPeople
FROM dbo.Monster AS m
INNER JOIN dbo.TagLookup AS tl
ON m.Name = tl.Name
INNER JOIN dbo.Tags AS t
ON t.ID = tl.ID
AND t.Value = 'green-skin';