我试图从laravel中的不同表中选择不同的表。在oracle中,我已经成功实现了查询并可以正常工作。现在,我正在尝试将其“翻译”成laravel。我该怎么办?
在oraclesql中,查询如下。 TEMP表以及此查询中使用的所有其他表都存在。是否可以使用DB :: raw做到这一点?你能给我我的建议吗?
INSERT INTO TEMP (OBJECT_TYPE, OBLECT_ID)
SELECT DISTINCT HRP1001_CG.OBJECT_TYPE, HRP1001_CG.OBJECT_ID FROM HRP1001_SC, HRP1001_CG, CONFIG
WHERE
(HRP1001_SC.OBJECT_TYPE = 'CG')
AND
(HRP1001_SC.REL_OBJ_TYPE = 'SC')
AND
(HRP1001_SC.REL_OBJ_ID = CONFIG.SC)
AND
((HRP1001_SC.ST_DATE < CONFIG.DES_DATE) AND (HRP1001_SC.END_DATE > CONFIG.DES_DATE))
AND
(HRP1001_CG.REL_OBJ_ID = HRP1001_SC.OBJECT_ID)
AND
((HRP1001_CG.OBJECT_TYPE ='CG') OR (HRP1001_CG.OBJECT_TYPE ='SM'))
ORDER BY HRP1001_CG.OBJECT_ID;
更新: 我也尝试了这段代码,但也没有收到结果:(。
$data = DB::table('hrp1001_sc')
->join('config', 'config.sc', '=', 'hrp1001_sc.rel_obj_id')
->join('config', 'config.des_date', '>', 'hrp1001_sc.st_date')
->join('config', 'config.des_date', '<', 'hrp1001_sc.end_date')
->join('hrp1001_cg', 'hrp1001_cg.rel_obj_id', '=',
'hrp1001_sc.object_id')
->where('hrp1001_sc.object_type', '=', 'cg')
->where('hrp1001_sc.rel_obj_type', '=', 'sc')
->select('hrp1001_sc.object_id')
->distinct()
->get();
答案 0 :(得分:0)
找到解决方案了,就是这样
$q = "insert into temp(object_type, object_id)";
$q = $q."select distinct hrp1001_cg.object_type, hrp1001_cg.object_id from
hrp1001_cg, hrp1001_sc, config where";
$q =$q." hrp1001_sc.object_type = 'CG'";
$q = $q." and hrp1001_sc.rel_obj_type = 'SC'";
$q = $q." and hrp1001_sc.rel_obj_id = config.sc";
$q = $q." and hrp1001_sc.st_date < config.des_date";
$q = $q." and hrp1001_sc.end_date > config.des_date";
$q = $q." and hrp1001_cg.rel_obj_id = hrp1001_sc.object_id";
$q = $q." and";
$q = $q." ((hrp1001_cg.object_type = 'CG') or (hrp1001_cg.object_type = 'SM'))";
$xx = DB::insert($q);