title: Find the store type which sells the maximum products in terms of sales amount & by quantity sold ? <SQL Server>
body: <p>For this question, I have a table named as 'Transactions' and the variables of this table are as follows :</p>
  
  <ul>
  <li>total_amt : It contains amount paid by customer when a transaction took place.</li>
  <li>Qty : It contains quantities ordered by customer of a particular product.</li>
  <li>prod_subcat_id : It contains products' subcategories ID</li>
  <li>prod_cat_id : It contains the products' category ID.</li>
  <li>store_type : It contains store type. It has 4 values - Flagship Stores, 
             Online, e-store, debcred</li>
  </ul>
  
  <p>Since the question demands that store type should sell maximum products by value of sales amount &amp; by value of quantities sold. So it might be a case where sales amount is max for a store type (lets say Store_A) but value of quantities sold is max for some other store type (lets say Store_B)
  But this is not the case with the given data. so whichever store_type holds the max Value of sales_Amt also holds the max value of quantities sold.</p>
  
  <p>Below is the query I have written so far. But it surely has some problem with alias names or something in the inline view or in the subquery. Also I have to achieve the output using subqueries in having clause.</p>
  
  <pre><code>select 
      store_type,
      sum(cast(total_amt as float)),
      sum(cast(Qty as int))
  from Transactions
  group by Store_type
  having 
      sum(cast(total_amt as float)) = 
      (
          select MAX(cast(total_amt as float))
          from(
              select SUM(cast(total_amt as float)) as col1 
              from Transactions
              group by Store_type
          )
      ) as T1 AND 
      sum(cast(Qty as int)) = 
      (
          select MAX(cast(Qty as int))
          from(
              select SUM(cast(Qty as int)) as col2
              from Transactions
              group by Store_type
          ) as T2
  </code></pre>