在此查询中,在
def typechecker(row):
type = row['Section']
animal = row['Animal']
if type == 'Mammal':
a = database.check(animal, 'Mammal')
return a
elif type == 'Amphib':
b = database.check(animal, 'Amphib')
return b
elif type == 'Insect':
c = database.check(animal, 'Insect')
return c
def format(self, row, col):
dataframe = pd.DataFrame(list(self.d()), columns=['Animal', 'Fruit', 'Transport', 'Section'])
a = dataframe.duplicated().tolist()
dataframe['Checker'] = dataframe.apply(typechecker, axis=1)
for i in range(len(dataframe)):
if dataframe['Checker'][i]. == 'Error':
if col == 2 and row == i:
return 'Red'
elif dataframe['Transport'][i] == '':
if col == 5 and row == i:
return 'Red'
elif dataframe['Animal'][i] is not None:
if ',' in dataframe['Animal'][i]:
if col == 4 and row == i:
return 'Red'
elif '\n' in dataframe['Animal'][i]:
if col == 4 and row == i:
return 'Red'
elif '\\n' in dataframe['Animal'][i]:
if col == 4 and row == i:
return 'Red'
elif '~' in dataframe['Animal'][i]:
if col == 4 and row == i:
return 'Red'
elif bool(a[i]) is True:
if row == i:
return 'Red'
else:
continue
表中,ODF_CA_NL_INIT_REQ_NOTE n
表中的每个记录可以有多个NL_NOTE
。一对多的关系。
我想为每个具有最新ODF_CA_OTHER o
的记录选择n.NL_NOTE
。
我添加了子选择,如下所示,但是对于查询中返回的每个记录,n.LAST_UPDATED_DATE
字段仅显示整个NOTE
表中的最新n.NL_NOTE
。
对于查询中返回的每个记录,如何显示每个相关记录的最新ODF_CA_NL_INIT_REQ_NOTE n
,而不是整个表?
n.NL_NOTE
谢谢
答案 0 :(得分:1)
一种实现方法是使用带有first/last
选项的解析函数:
select o.nl_direct as director, o.nl_prior as priority,
(select max(nl_notes) keep (dense_rank last order by last_updated_date)
from odf_ca_nl_init_req_note n where n.odf_parent_id = o.id) as note
from odf_ca_other o