看看下面的SQL语句吧,虽然复杂,可是能解决问题。不过,“么贴术”是什么东西呀,它的scno与第一个表table1匹配不上,为什么也会出现在结果里呀。我的这个是不包含它的,如果有它还要在改动一下。
SELECT t1.scno, t2.name, t1.num1, t1.color1
FROM table2 t2, table1 t1
WHERE t2.scno = t2.scno AND t2.Type = 1
UNION
SELECT t1.scno, t2.name, t1.num2, t1.color2
FROM table2 t2, table1 t1
WHERE t2.scno = t1.scno AND t2.Type = 1
UNION
SELECT t1.scno, t2.name, t1.num3, t1.color3
FROM table2 t2, table1 t1
WHERE t2.scno = t1.scno AND t2.Type = 1
UNION
SELECT t1.scno, t2.name, t1.num1 + t1.num2 + t1.num3, ''
FROM table2 t2, table1 t1
WHERE t2.scno = t1.scno AND t2.Type = 0
|