PRQL – A proposal for a better SQL
Now this is actually nice, unlike the other suggestion posted today[1].<p>Maybe I&#x27;m just too used to non-standard extensions of our database but the SQL example could, at least for our db, be rewritten as<p><pre><code>    SELECT TOP 20
        title,
        country,
        AVG(salary) AS average_salary,
        SUM(salary) AS sum_salary,
        AVG(gross_salary) AS average_gross_salary,
        SUM(gross_salary) AS sum_gross_salary,
        AVG(gross_cost) AS average_gross_cost,
        SUM(gross_cost) AS sum_gross_cost,
        COUNT(*) as count
    FROM (
        SELECT
            title,
            country,
            salary,
            (salary + payroll_tax) AS gross_salary,
            (salary + payroll_tax + healthcare_cost) AS gross_cost
        FROM employees
        WHERE country = &#x27;USA&#x27;
    ) emp
    WHERE gross_cost &gt; 0
    GROUP BY title, country
    ORDER BY sum_gross_cost
    HAVING count &gt; 200
</code></pre>
This cuts down the repetition a lot, and can also help the optimizer in certain cases. Could do another nesting to get rid of the HAVING if needed.<p>Still, think the PRQL looks very nice, especially with a &quot;let&quot; keyword as mentioned in another thread here.<p>[1]: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=30053860" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=30053860</a>