我的观看数据如下:
Country qty Amt type
India 42 1000 1
India 32 59 2
我正在尝试根据国家/地区对视图数据进行非规范化,因此,两行应显示为一行。
Country qty Amt type qty Amt type
India 42 1000 1 32 59 2
由于我是MySQL的新手,所以有人可以帮我吗...
答案 0 :(得分:1)
一种方法是def monkeypatchsetattr(obj, oldsetattr):
def newsetattr(key, value):
# hasattr(self, key) will return true if key is an attrib of baz
# and so is not a good test
if key is self.__dict__:
oldsetattr(key, value)
else:
setattr(obj.baz, key, value)
return newsetattr
class Baz():
pass
class Qux():
def __init__(self):
self.name = None
self.color = 'red'
self.baz = Baz()
self.__setattr__ = monkeypatchedselfattr(self, self.__setattr__)
def __getattr__(self, item):
return getattr(self.baz, item)
def __setattr__(self, item, value):
if hasattr(self, item):
super(Qux, self).__setattr__(self, item, value)
else:
setattr(self.baz, item, value)
:
join
答案 1 :(得分:0)
我假设您要合并的不仅是一两行,而是n行(如果有印度行的话)应该是一行。在这种情况下,您可以简单地使用自我联接。
select * from t as t1,t as t2 where t1.country = t2.country