1、先给B表添加主键列
alter table tableB add constraint b_PK primary key(date,channel)
2、将B表的组合主键关联到A表的外键组合键中
alter table tableB add constraint tableB_fk foreign key(date,channel) references tableA (date,channel) on DELETE CASCADE
3 delete from tableA where date =? and channel =? 就出发相关记录··~
首先能实现目的的语法是这么写:select id,name,a_rankfrom table_a,(select a_id,count(*) as a_rankfrom table_bgroup by a_id)where table_a.id = table_b.a_idorder by a_rank
学生表:stu。选课表:sc。代码如下已测试通过。select stu.sname,count(sc.cname) as '选修总数目' from stu,sc where stu.sid=sc.sid group by stu.sname order by count(sc.cname) desc limit 0,7
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)