mysql> select * from a; +------+--------+ | a_id | a_b_id | +------+--------+ | 1 | 1 | | 2 | 2 | +------+--------+ |
mysql> select * from b; +--------+--------+-----+------+ | a_b_id | b_c_id | won | lost | +--------+--------+-----+------+ | 1 | 1 | 100 | 200 | | 2 | 2 | 300 | 500 | +--------+--------+-----+------+ |
mysql> select * from c; +--------+--------+-------+ | b_c_id | c_d_id | point | +--------+--------+-------+ | 1 | 1 | 1000 | | 1 | 1 | 2000 | +--------+--------+-------+ |
mysql> select a.a_id,b.won,b.lost,c.point from a left join b on a.a_b_id=b.a_b_id left join c on b.b_c_id=c.b_c_id; |
+------+------+------+-------+ | a_id | won | lost | point | +------+------+------+-------+ | 1 | 100 | 200 | 1000 | | 2 | 300 | 500 | 2000 | +------+------+------+-------+ 2 rows in set (0.00 sec) |
原帖由 cenalulu 于 2009-6-12 17:59 发表
问题2的需求还是不明确。
“而我想把在表c中point 为1,2这最后2名的c_d_id改为2也就是c会变成”
那么整个update的过程与d表有什么关系?
与d表插入的那一行又有什么关系?
是每当d插入新行就对c进行操作 ...
update c set c.c_d_id = c.c_d_id + 1 where 2 > (select count(*) from c as tmp where tmp.point < c.point) |
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |