相当复杂......我有两个表,t1 包含有关特定对象的描述信息,第二个表 t2 包含用于解码 t1 中的对象的信息。
我将尝试提供一个简单的示例:
----
t1 (Name, Type, Size, Color)
----
dog1 - mammal - big - brown
dog2 - mammal - big - black
cat1 - mammal - small - black
fish1 - fish - small - gold
---
t2 (Type, Size, Color, Value)
---
mammal - "" - blue - 1
mammal - big - brown - 0.5
mammal - big - black - 0.75
mammal - small - "" - 2
fish - big - "" - 5
fish - small - "" - 0.5
fish - small - gold - 0.5
"" - "" - black - 1
"" - big - "" - 0.75
---
result(name, value)
---
dog1 - 1.25 //receives a value of 1.25 (0.5+0.75) because it hits the row of being mammal/big/brown (0.5) and the extra hit of just being big (0.75)
dog2 - 2.5 // 0.75 + 1 + 0.75 for being mammal/big/black (0.75), for being black (1), and for being big (0.75)
cat1 - 2 //2 for being mammal/small
fish1 - 1 // 0.5 + 0.5 for being fish/small and fish/small/gold
---
这是我当前的查询,因为它与此示例有关,但由于多种原因,它当然不起作用。
Select t1.Name, SUM(counter.Value) as Sums
From
(Select *
From t1, t2
where t1.Type = t2.Type and t1.Size = t2.Size and t1.Color = t2.Color)