SELECT 
    CASE WHEN tsl.line_discount_amount > 0 THEN "Discounted" ELSE "Regular" END as sale_type,
    COUNT(DISTINCT t.id) as transaction_count,
    SUM(tsl.quantity) as total_quantity,
    SUM(t.final_total) as total_revenue
FROM transactions t
JOIN transaction_sell_lines tsl ON t.id = tsl.transaction_id
WHERE t.type = "sell" AND t.status = "final"
GROUP BY CASE WHEN tsl.line_discount_amount > 0 THEN "Discounted" ELSE "Regular" END;