这样的sql语句怎样组建?
Arias 2005-12-07 10:09:09 有4个表 :
test1 test2 test3
id serviceid mocmd pid serviceid itemid serviceid itemid fsStr
25 1 'A' 25 1 1 1 1 'A'
26 1 'B' 26 1 1 1 1 'B'
27 1 'C' 27 1 1 1 1 'C'
28 1 'B' 28 1 1 1 1 ''
29 1 '' 29 1 1 1 2 'a'
30 1 '' 30 1 1 1 2 'b'
31 1 'a' 31 1 2 1 2 ''
32 1 'b' 32 1 2
33 1 '' 33 1 2
test4
itemid serviceid
1 1
2 1
其中3个表之间的关系是 :
test1.id = test2.pid
test1.serviceid = test2.serviceid = test3.serviceid
test2.itemid = test3.itemid
test3.itemid = test4.itemid
现在要统计在表test1 中 这些fsStr出现的百分率 ,按itemid serviceid分组的
希望得到的结果是 :
serviceid itemid fsStr num percent
1 1 'A' 1 1/(1+2+1+2)
1 1 'B' 2 2/6
1 1 'C' 1 1/6
1 1 '' 2 2/6
1 2 'a' 1 1/(1+1+1)
1 2 'b' 1 1/3
1 2 '' 1 1/3
不知道能否实现这样要求,希望高手指点!!!