我是mysql表
a id title num1 a 4
2 b 2
3 c 2bid aid title
1 1 aa
2 1 bb
3 1 cc
4 1 ee5 2 pp
6 2 ee
7 3 ii
8 3 tttcid bid aid1 2 1
2 4 1
3 6 2 我是根据c表删除对应b表的相同数据 同时修改a表记录num的条数可以给几条sql完成
如果不行可以和php代码完成
a id title num1 a 4
2 b 2
3 c 2bid aid title
1 1 aa
2 1 bb
3 1 cc
4 1 ee5 2 pp
6 2 ee
7 3 ii
8 3 tttcid bid aid1 2 1
2 4 1
3 6 2 我是根据c表删除对应b表的相同数据 同时修改a表记录num的条数可以给几条sql完成
如果不行可以和php代码完成
-- phpMyAdmin SQL Dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2009 年 05 月 20 日 03:10
-- 服务器版本: 5.0.51
-- PHP 版本: 5.2.6SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";--
-- 数据库: `up`
---- ----------------------------------------------------------
-- 表的结构 `a`
--CREATE TABLE `a` (
`id` int(255) NOT NULL auto_increment,
`titile` varchar(255) NOT NULL,
`num` int(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;--
-- 导出表中的数据 `a`
--INSERT INTO `a` (`id`, `titile`, `num`) VALUES
(1, 'a', 4),
(2, 'b', 2),
(3, 'c', 2);-- ----------------------------------------------------------
-- 表的结构 `b`
--CREATE TABLE `b` (
`id` int(50) NOT NULL auto_increment,
`aid` int(50) NOT NULL,
`title` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;--
-- 导出表中的数据 `b`
--INSERT INTO `b` (`id`, `aid`, `title`) VALUES
(1, 1, 'aa'),
(2, 1, 'bb'),
(3, 1, 'cc'),
(4, 1, 'dd'),
(5, 2, 'pp'),
(6, 2, 'ee'),
(7, 3, 'ii'),
(8, 3, 'ttt');-- ----------------------------------------------------------
-- 表的结构 `c`
--CREATE TABLE `c` (
`id` int(5) NOT NULL auto_increment,
`aid` int(5) NOT NULL,
`bid` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;--
-- 导出表中的数据 `c`
--INSERT INTO `c` (`id`, `aid`, `bid`) VALUES
(1, 2, 1),
(2, 4, 1),
(3, 6, 2);
delete b from b,c where b.id=c.bid 是要这个效果?(2)
先分组求出出统计结果:select aid,count(*) from b group by aid;然后循环更新:update a set num=4 where id=1;
update a set num=2 where id=2;
update a set num=3 where id=2;或者直接truncate table a;
insert into a(id,titile,num) select aid,title,count(*) from b group by aid;
2.select count(*) as aid from b group by aid;
update a set num=上面统计出来的数据 where id=1;
2.$sql="select count(*) as aid from b group by aid";
$ret=mysql->query($sql);
$nums=mysql_num_rows($ret);
update a set num=$nums left join b on(a.id=b.aid) where a.id=b.aid;
insert into a(id,titile,num) select aid,title,count(*) from b group by aid;
这语句是重建表a数据的