worker表 工人表
create table worker    --务工人员表
(
        worker_Id         int primary key not null,    --务工人员id            
        worker_Name    varchar2(20) not null,      --务工人员真实姓名       
        sex                  int not null,                                            --性别    
        living_Place      int references region(region_Id) not null,    --现居住地
        hu_Ji               int references region(region_Id) not null      --户籍 
)
create table region         --行政区划(省,市,区县)
(
      region_Id           int primary key     not null,        --行政区划 id
      region_Name      varchar2(40)     not null   --行政区划名称 
)怎么样一次查出居住地名称和户籍名称呢?我建的报  "未明确定义列" 错误

解决方案 »

  1.   

    create table region         --行政区划(省,市,区县)
    (
          region_Id           int primary key     not null,    
          region_Name         varchar2(40)     not null 
    );
    create table worker  
    (
            worker_Id          int primary key not null,  
            worker_Name        varchar2(20) not null, 
            sex                int not null,                               
            living_Place       int references region(region_Id) not null, 
            hu_Ji              int references region(region_Id) not null    
    );select w.worker_Id 
         , w.worker_Name 
         , r.region_Name living_Place
         , r.region_Name hu_Ji 
    from   worker w
         , region r 
    where  w.living_Place = r.region_Id;
      

  2.   


     select worker_id, worker_name, (select region_Name from region b where b.region_id = a.living_place) living_Place,(select region_Name from region b where b.region_id = a.hu_ji) hu_ji from worker a
      

  3.   

    1、1楼的有问题,只能查出一个2、2楼的也不错,但是子查询与连接查询还是有区别的,推荐使用连接查询
     
    select w.worker_Id 
         , w.worker_Name 
         , a.region_Name living_Place
         , b.region_Name hu_Ji 
    from   worker w inner join  region a
    on  w.living_Place = a.region_Id
    inner join  region b
    on  w.living_Place = b.region_Id