Skip to content

Commit

Permalink
Create s.sql
Browse files Browse the repository at this point in the history
Signed-off-by: MolfarUA <52976230+MolfarUA@users.noreply.github.com>
  • Loading branch information
MolfarUA authored Sep 19, 2024
1 parent b3d2add commit b8d78b6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 5 kyu/Count IP Addresses/s.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT id, last::inet - first::inet as ips_between
FROM ip_addresses;
________________
SELECT
DISTINCT id,
(d4+d3*256+d2*256*256+d1*256*256*256) as ips_between
FROM
(SELECT *,
cast(split_part(last,'.',1) as bigint) - cast(split_part(first,'.',1) as bigint) as d1,
cast(split_part(last,'.',2) as bigint) - cast(split_part(first,'.',2) as bigint) as d2,
cast(split_part(last,'.',3) as bigint) - cast(split_part(first,'.',3) as bigint) as d3,
cast(split_part(last,'.',4) as bigint) - cast(split_part(first,'.',4) as bigint) as d4
FROM ip_addresses) as ip;
________________
SELECT id, last::inet - first::inet AS ips_between FROM ip_addresses ORDER BY id;

0 comments on commit b8d78b6

Please sign in to comment.