How to insert data from 2 other tables in oracle

时间:2017-12-18 07:57:45

标签: sql oracle

I'm making a new table. The value/data in the table are taken from another table. for example: in SELECT DISTINCT T1.BPT, T1.BC, T1.ST FROM Mytable T1 WHERE T1.BPT IN ('NH') AND (T1.BC = 'ABH6G' OR T1.BC IS NULL); I have field table A with 2 data, Code and EXE. In IMP I have field table B with data Year and 2016. Now i need to make 2017 with field table C where the data in field Status are Status, EXE-2016, IMP-2016 and EXE-2017. How was the query for this kind of problem?

IMP-2017

4 个答案:

答案 0 :(得分:0)

In your case, it's better to create a Class MyClass { ObservableCollection<pojo> myCollection {get;set;} MyClass() { calendarmstrDG.DataContext = myCollection; } public void AddData() { myCollection.Add(new pojo(){ // Add Values }); } public void Save_Btn_Click(object sender, RoutedEventArgs e) { foreach(pojo items in myCollection) { // here get items using items.Prefix/year/.... } } } in such a way to record view for later usage like a table :

sql

D e m o

答案 1 :(得分:0)

您希望从两个表中交叉连接记录:

  • 表A中的每条记录
  • 每年从表B中以MAX标志(即'Y'胜过'N')

然后使用CREATE TABLE c AS <query>从查询结果中创建表C.

create table c as
select a.code || '-' || bb.year as status, bb.flag
from a
cross join
(
  select year, max(flag) as flag
  from b
  group by year
) bb;

(也许BarbarosÖzhan是对的,你实际上想要创建一个视图。然后使用create view c as <query>。)

答案 2 :(得分:-1)

$AxiosXHR

答案 3 :(得分:-1)

CREATE table C as 
SELECT A.Code || '-' || B.Year AS 
STATUS , B.flag
FROM A,B