2.1 Current value reference

 

1.2 Structured data


Calculate the sum of the first 100 odd numbers.

SPL

A
1 =to(100)
2 =A1.sum(~*2-1)

A1.sum(~*2-1) is equivalent to A1.(~*2-1).sum().

SQL

SELECT SUM(2 * LEVEL - 1) AS sum_of_odd_numbers
FROM dual
CONNECT BY LEVEL <= 100;

Python

l=[i for i in range(1,101)]
s=pd.Series(l)
odd_sum=s.apply(lambda x:x*2-1).sum()

Example codes for comparing SPL, SQL, and Python