任何人都可以帮我这个忙,我是数据库和查询的新手。我正在使用sqlite;我的数据库包含2个表。边缘和节点。 表格就像:
nodes
_______________________
NO name family
9808 antony bits
6757 saly wood
edges
_______________________
ID Source Target
1 9808 6757
2 9808 6757
3 6757 9808
4 6757 9808
5 9808 6757
查询应将源和目标替换为“名称和家庭”和“名称和家庭”,然后计算每个边的频率,从而得出以下结果:
Source target frequency
"antony bits" "saly wood" 3
"saly wood" "antony bits" 2
答案 0 :(得分:1)
以.mode column
开始,然后运行以下查询:
select a.name||' '||a.family as source, b.name||' '||b.family as target, count() as freq from edges as c
left join nodes as a on c.source = a.NO
left join nodes as b on c.target = b.NO
group by source, target
order by freq desc ;
输出为:
source target freq
----------- ---------- ----------
antony bits saly wood 3
saly wood antony bits 2
诀窍是在源列和目标列上双联接表。