我在PostgreSQL 9.5数据库中有一些示例数据,如下所示:
def gen_records(record_name, img_path_file, label_map):
writer = tf.python_io.TFRecordWriter(record_name)
classes = []
with open(label_map, 'r') as f:
for l in f.readlines():
classes.append(l.split(',')[0])
with open(img_path_file, 'r') as f:
lines = f.readlines()
num_images = len(lines)
print 'total number to be written' + str(num_images)
print 'start writing...'
patches = []
with open(img_path_file, 'r') as f:
for patch in f.readlines():
patches.append(patch[:-1])
cnt = 0
for patch in patches:
cnt += 1
# print '[' + str(cnt) + ' / ' + str(num_images) + ']' + 'writing ' + str()
img = tf.image.resize_images(np.array(Image.open(patch)), (224, 224), method=tf.image.ResizeMethod.BILINEAR)
img_raw = np.array(img).tostring()
label = classes.index(patch.split('/')[1])
example = tf.train.Example(features=tf.train.Features(feature={
'label': _int64_feature(int(label)),
'image': _bytes_feature(img_raw)
}))
writer.write(example.SerializeToString())
writer.close()
对于每个组,我想使用PostgreSQL Group length
A 19.3
A 19.3
A 20.3
A 20.3
A 19.3
A 19.3
B 22.1
B 19.3
B
B 15.5
B 12.8
B 14.7
函数有条件地找到模式(最重复/常用值),这样:
所需的输出可能如下:
mode()
我如何有条件地找到模式,有人可以帮助我吗?
答案 0 :(得分:2)
我认为你的条件都归结为:
select group,
mode() within group (order by coalesce(length, 0.0) desc)
from t
group by group
如果您有group
行,则mode()
无法返回NULL
,因此不需要进一步外COALESCE()
。