我不知道这个问题的标题是否正确, 但这是我的问题
我有两个表(TB1和TB2)都有相同的列,这里是结构..
from __future__ import unicode_literals
from django.db import models
class Customer(models.Model):
name = models.CharField(max_length=120)
address1 = models.CharField(max_length=120)
address2 = models.CharField(max_length=120)
city = models.CharField(max_length=50)
state = models.CharField(max_length=50)
zip = models.IntegerField()
country = models.CharField(max_length=50)
def __str__(self):
return self.name
然后我要比较 table_name 中的所有值 table_name 和 data_type
返回表应该至少看起来像这样(带有样本数据)......
TABLE_NAME | COLUMN_NAME | DATA_TYPE
抱歉,但我还没有开始任何查询,因为我真的不知道从哪里开始......
提前感谢所有回复的人:D
答案 0 :(得分:1)
我想你想要一个full outer join
:
select coalesce(tb1.table_name, tb2.table_name) as table_name,
tb1.column_name, tb2.column_name,
coalesce(tb1.data_type, tb2.data_type) as data_type
from tb1 full outer join
tb2
on tb1.table_name = tb2.table_name and
tb1.column_name = tb2.column_name and
tb1.data_type = tb2.data_type;