Title: I have been writing a decent amount of SQL for three years now, and while the paradigm is extremely powerful, the language lends itself to unmaintainable spaghetti code quickly.<p>Fundamentally, SQL lacks meaningful abstraction, and there&#x27;s no sane way to package very common operations.<p>Say you want to find elements in a row that correspond to some maximum value when grouped by date. Today, you&#x27;d need to write something like this EVERY SINGLE TIME:<p>```
SELECT 
    sd1.sale_person_id,
    sd1.sale_person_name,
    sd1.no_products_sold,
    sd1.commission_percentage,
    sd1.sales_department
FROM
    sales_department_details sd1
        INNER JOIN
    (SELECT 
        sale_person_id, MAX(no_products_sold) AS no_products_sold
    FROM
        sales_department_details
    GROUP BY sale_person_id) sd2 
ON sd1.sale_person_id = sd2.sale_person_id
AND sd1.no_products_sold = sd2.no_products_sold;
```<p>Wouldn&#x27;t something like this be nicer?<p>```
SELECT
  sale_person_id,
  max(no_products_sold) as max_sold,
  link(sale_person_name,  max_sold),
FROM
 sales_department_details
```<p>Frankly, it seems like some sort of macro system is needed. Perhaps the SQL  compiles into the above?
Upvote: