我有两张看起来像这样的表:
带有字段的检查点:
Checkpoint_id
Checkpoint_name
checkpoint_id是主键
Checkpoint_data包含字段:
Checkpoint_id
sequence_number
data
(checkpoint_id,sequence_number)是主键
我想要做的是获取checkpoint_id及其名称,还总结通过checkpoint_id链接的所有数据的长度。例如,我想获得sequence_number 1,2,3和4的长度,然后将所有数据的长度相加,并返回相应的检查点ID和名称。数据字段是varchar
答案 0 :(得分:4)
SELECT c.checkpoint_id, c.checkpoint_name, sum(length(cd.data))
FROM checkpoint c
INNER JOIN checkpoint_data cd ON c.checkpoint_id = cd.checkpoint_id
GROUP BY c.checkpoint_id
编辑:
SELECT c.checkpoint_id, c.checkpoint_name, sum(length(cd.data))
FROM checkpoint c
INNER JOIN checkpoint_data cd ON c.checkpoint_id = cd.checkpoint_id
GROUP BY c.checkpoint_id, c.checkpoint_name
答案 1 :(得分:-1)
有两列:first_name,last_name into table employees。
SELECT first_name,
last_name,
LENGTH(first_name)+LENGTH(last_name)
as "Length of name" FROM employees;