表“标签”:
Source Target Weight
#003 blitzkrank 0.83
#003 deutsch 0.7
#003 brammen 0.57
#003 butzfrauen 0.55
#003 solaaaa 0.5
#003 moments 0.3
college scandal 1.15
college prosecutors 0.82
college students 0.41
college usc 0.33
college full house 0.17
college friends 0.08
college house 0.5
college friend 0.01
该表在“Source”列中有5.600.000行和~91.000个唯一条目。
对于“Source”和“Target”中的每个唯一值,我需要按权重(表按“Source”(升序)和“Weight”(降序)排序)的前x%行(例如,前20%,前30%,需要可变)。
由于会有重复项(例如,“Source=”college“将产生至少一个重复行作为”Target“=”丑闻“),如果可能,应删除重复项。否则没什么大不了的。
计算“源”:
6 rows where Source = "#003", 6 * 0.2 = 1.2 = take 1 row
8 rows where Source = "college", 8 * 0.2 = 1.6 = take 2 rows
Source Target Weight
#003 blitzkrank 0.83
college scandal 1.15
college prosecutors 0.82
如何在SQLite数据库中的SQL中实现这一点?