数据库统计··问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 02:35:29
统计表1中·xuehao字段·相同学号的学生信息条数并记录在·表2·jilu字段
怎么写代码··可用+30分

select count(distinct(t1.学号)) from 表1 t1, 表1 t2 where t1.xuehao = t2.xuehao;

update 表2
set jilu = (select count(distinct(t1.学号))
from 表1 t1, 表1 t2
where t1.xuehao = t2.xuehao)

select * from 表1,表2 where 表1.xuehao=表2.jilu



select * from 表1 inner jion 表2 on 表1.xuehao=表2.jilu

$query=mysql_query("select xuehao,count(*)as num from 表1 group by xuehao");
while($result=mysql_fetch_array){
$query1=mysql_query("insert into 表2 jilu values('$result[num]')where xuehao='$result[xuehao]' ");
}