How can I perform this SQL code in SPL?
Data transformation is the process of converting raw data into a structured format that is more suitable for analysis, reporting, or other downstream tasks. In context, let’s say we want to generate a report showing the top three languages spoken in each country, along with the percentage of speakers for each language.
WITH RankedLanguages AS (
SELECT
cl.CountryCode,
cl.Language,
cl.Percentage,
ROW_NUMBER() OVER (PARTITION BY cl.CountryCode ORDER BY cl.Percentage DESC) AS LanguageRank
FROM
CountryLanguage cl
),
TopThreeLanguages AS (
SELECT
rl.CountryCode,
rl.Language,
rl.Percentage
FROM
RankedLanguages rl
WHERE
rl.LanguageRank <= 3
)
SELECT
c.Name AS Country,
ttl.Language AS TopLanguage,
ttl.Percentage AS PercentageOfSpeakers
FROM
TopThreeLanguages ttl
JOIN
Country c ON ttl.CountryCode = c.Code;
Result:
How can I perform similar script using esProc SPL?
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL
Hi, thanks. The code worked, but here is the correct code.
=connect@l(“MySQL”)
=A1.query(“select * from countrylanguage”)
=A2.groups(countrycode;top(-3;percentage):top3).conj(top3)
=A1.query(“select code,name from country”)
=A3.switch(countrycode,A4:code).new(countrycode.name,language,percentage)
I changed the ‘code’ name to countrycode