利用已存在的表创建另一个表;三表关联查询

利用已存在的表创建另一个表(oracle,mssql,mysql)

//利用已存在的test表来创建 test2表
oracle :
create table test2 as select * from test(创建表结构和里面的数据)
 
create table test2 as select * from test where 1=2(只创建表结构)
mssql:
select   *  into   customer3   from   customer 
 
mysql:
同oracle
create table customer2 as select * from customer


//如果是要生成指定的列名呢请看 (这里只介绍oracle的,语法上掌握以后,原理是一样的)
若只有customer的id和name字段并且在customer2中表结构是(cid,c_name);
那么可以这么写
create table customer2  select id cid,name c_name from customer
可以看出只是指定别名而已 ,mysql中是一样的,mssql2000只是语法不一样,但原理相同

--------------------------------------------------------------------------------
sql复杂查询语句问题求救:列出选修了三门以上课程的学生和课程名.
stuinfo 学生信息表
scourse 课程信息表
examscoure 成绩信息表

select s.stuno, s.stuname, c.courseno,c.name
  from stuinfo s, scourse c, examscoure e
 where s.stuno = e.stuno
   and c.courseno = e.scourcno
   and s.stuno IN (SELECT s.stuno
                     from stuinfo s, examscoure e
                    where s.stuno = e.stuno
                    GROUP BY s.stuno
                   HAVING COUNT(e.stuno) >= 3)

猜你喜欢

转载自ych0108.iteye.com/blog/1927351