首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql 删除有关问题。 所有分了。

2012-02-29 
mysql 删除问题。 所有分了。。2个表tableAtableb其中b的id与A的id值相同。根据tableA中的type分组、统计记录合

mysql 删除问题。 所有分了。。
2个表
tableA
tableb
其中b的id   与   A的id   值相同。


根据   tableA中的   type   分组、统计记录合。找到大于100条记录的type

删除每个大于100条记录的   type     100条以后的所有记录。   同时删除,tableB中相对应的记录

[解决办法]


DELETE bill,payment FROM bill,payment WHERE bill.pay_id = payment.pay_id AND payment.charge=(select charge from (select charge,count(*) c from payment group by charge having c> 2) n)

试试
[解决办法]
这里 A 代表 tableA,B代表tableB。

delete from tableA,tableB where B.id = A.id and A.id in ( select id from A where type in (select type, count(*) as counttype from A where 1 group by tableA.type having counttype > 100) )

以上应该已经实现了。
[解决办法]
哎,MySQL5的新特性不怎么熟了。楼上的两层子查询,以前可不敢想的啊!叹一个……
[解决办法]
顶一个先

热点排行