What type of sql query would I use to turn the following;
| ID | SERIAL | LCN | INITLCN |
|------|----------|-------|---------|
| 1 | A | A1 | |
| 2 | B | A2 | |
| 3 | C | A3 | A1 |
| 4 | D | A4 | A2 |
| 5 | E | A5 | A1 |
|------|----------|-------|---------|
into a result similar to this;
| ID | COUNT |
|------|---------|
| 1 | 2 |
| 2 | 1 |
|------|---------|
Using my low SQL skills, I have managed to write the below query however it is extremely slow;
select
a.id,
count (b.id) as parent
from assets a
left join assets b
ON (a.lcn = b.initlcn)
group by a.id
order by a.id;