//查询部门 $sql_depart="SELECT * FROM depart WHERE gid>0 AND gid $query_depart=$db->query($sql_depart); while($d=$db->fetch_array($query_depart)){ ?>
//查询人员
$sql_user="SELECT * FROM members WHERE flag $query_user=$db->query($sql_user); while($u=$db->fetch_array($query_user)){ ?>
//查询所有日志 $sql="SELECT c1.*,c2.* FROM log c1 LEFT JOIN log_time c2 ON (c1.time_id=c2.tid) WHERE c2.year='".$year."' AND c1.userid='".$u['uid']."' AND c2.end_date $query=$db->query($sql); while($row=$db->fetch_array($query)){
SELECT d.*,m.*,l.* FROM depart d left join members m on m.flag left join (SELECT c1.*,c2.* FROM log c1 LEFT JOIN log_time c2 ON (c1.time_id=c2.tid) WHERE c2.year='".$year."' AND c2.end_date WHERE d.gid>0 AND d.gid
写成一个语句了~
desc sql 关键字段创建索引
不知道下面这个SQL能不能让你的速度快些(不保证该SQL正确可行)
SELECT d.*,m.*,l.* FROM depart d left join members m on m.flag left join (SELECT c1.*,c2.* FROM log c1 LEFT JOIN log_time c2 ON (c1.time_id=c2.tid) WHERE c2.year='".$year."' AND c2.end_date WHERE d.gid>0 AND d.gid
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论