请益各位高手大大,
有3个相同的column的表格,但是内容不同。表格如下:
a2 a4 a6
pid session a2a a2b pid session a4a a4b pid session a6a a6b
==================== ==================== ====================
1 test 1 0 1 test 0 0 1 test 1 0
2 try 0 1 2 try 1 1 2 try 0 1
合并3个表格成为一个的程式如下:
SELECT a2.session,a2.a2a,a2.a2b,a4.a4a,a4.a4b,a6.a6a,a6.a6b
FROM a2
JOIN a4 ON a4.session = a2.session
JOIN a6 ON a6.session = a4.session
得到的结果就是:
session a2a a2b a4a a4b a6a a6b
================================
test 1 0 0 0 1 0
try 0 1 1 1 0 1
我想请益的问题,我想要做每个session的平均值该如何写?
session a2a a2b a4a a4b a6a a6b avg
====================================
test 1 0 0 0 1 0 ?
try 0 1 1 1 0 1 ?
我写的语法是:
SELECT "a2.session,a2.a2a,a2.a2b,a4.a4a,a4.a4b,a6.a6a,a6.a6b
AND AVG(a2.a2a+a2.a2b+a4.a4a+a4.a4b+a6.a6a+a6.a6b)/6
FROM a2
JOIN a4 ON a4.session = a2.session
JOIN a6 ON a6.session = a4.session
WHERE `session` LIKE '".$_SESSION["loginMember"]."'";
<table width="1200" border="1">
<tr>
<td align='center'><div align="center">session</div></td>
<td align='center'><div align="center">a2a</div></td>
<td align='center'><div align="center">a2b</div></td>
<td align='center'><div align="center">a4a</div></td>
<td align='center'><div align="center">a4b</div></td>
<td align='center'><div align="center">a6a</div></td>
<td align='center'><div align="center">a6b</div></td>
</tr>
<?php
$bgcolor = "";
$content = "";
mysql_data_seek($result, 0);
while($record=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$record['session']."</td>";
echo "<td>".$record['a2a']."</td>";
echo "<td>".$record['a2b']."</td>";
echo "<td>".$record['a4a']."</td>";
echo "<td>".$record['a4b']."</td>";
echo "<td>".$record['a6a']."</td>";
echo "<td>".$record['a6b']."</td>";
echo "</tr>";
}
?>
</table>
请问如何让黄色的avg出现?
谢谢各位大大帮忙