By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE finaltable(i INT);
INSERT INTO finaltable VALUES (1),(2),(3)
3 rows affected
CREATE TABLE new(i INT, cnt INT);
INSERT INTO new(i, cnt)
SELECT i, COUNT(*) OVER()
FROM finaltable
3 rows affected
SELECT * FROM new
i | cnt |
---|---|
1 | 3 |
2 | 3 |
3 | 3 |
INSERT INTO new(i, cnt)
SELECT i, COUNT(*) OVER()
FROM finaltable
WHERE i <=2
2 rows affected
SELECT * FROM new
i | cnt |
---|---|
1 | 3 |
2 | 3 |
3 | 3 |
1 | 2 |
2 | 2 |