SQL中cross join,left join,right join ,full join,inner join 的区别
cross join 是笛卡儿乘积 就是一张表的行数乘以另一张表的行数
left join 第一张表的连接列在第二张表中没有匹配是,第二张表中的值返回null
right join 第二张表的连接列在第一张表中没有匹配是,第一张表中的值返回null
full join 返回两张表中的行 left join+right join
inner join 只返回两张表连接列的匹配项
right join 第二张表的连接列在第一张表中没有匹配是,第一张表中的值返回null
full join 返回两张表中的行 left join+right join
inner join 只返回两张表连接列的匹配项
- insert into t_sales_forecast
- select SALES_FORECAST_SEQUENCE.nextval as id,basic.* from
- (
- select school_id,district_id,year_table.year,month_table.month ,500 as or_forcast,1000 as re_forcast,sysdate as update_date,'1' as user_id,sysdate as insert_date
- from v_school_district
- cross join
- (
- select level as year from dual where level>2006 connect by level<2012
- ) year_table
- cross join
- (
- select lpad(level,2,0) month from dual connect by level <13
- ) month_table
- order by school_id,district_id,year_table.year,month_table.month
- ) basic