title: Need to verify if my SQL queries are correct
body: <h1>Description of Tables</h1>
  
  <p>There are three tables involved in this question: <code>transactions</code>, <code>segments</code> and
  <code>products</code>, which simulate a simplified retail data schema.  Here is a semantic
  description of the tables:</p>
  
  <ol>
  <li><code>transactions</code>: contains detailed information about each product a customer
  has purchased.  A transaction consists of one or more products purchased by
  a customer indexed by a unique transaction id.
  
  <ul>
  <li><code>trans_id</code>: the transaction id</li>
  <li><code>cust_id</code>: the customer id</li>
  <li><code>prod_id</code>: the product id</li>
  <li><code>item_qty</code>: the quantity of the product that is being purchased</li>
  <li><code>item_price</code>: the per unit price of the product (NOTE: the total revenue
  for a product is <code>item_qty * item_price</code>)</li>
  </ul></li>
  <li><code>products</code>: contains detailed attributes about each product.
  
  <ul>
  <li><code>prod_id</code>: the product id (same meaning as in <code>transactions</code>)</li>
  <li><code>prod_name</code>: the product name</li>
  <li><code>brand</code>: the brand of the product</li>
  <li><code>category</code>: the category of the product</li>
  </ul></li>
  <li><code>segments</code>: contains a history of customer segmentation labeling for each
  customer.  Segments are computed periodically for all current customers and
  appended to the table after each computation.  The current (most up to date)
  active segment for each customer is specified by <code>active_flag = 'Y'</code> column.
  
  <ul>
  <li><code>cust_id</code>: the customer id (same meaning as in <code>transactions</code>)</li>
  <li><code>seg_name</code>: the segment of this customer</li>
  <li><code>update_dt</code>: the date when this segment was updated</li>
  <li><code>active_flag</code>: whether or not this segment is the active segment for this customer</li>
  </ul></li>
  </ol>
  
  <p>QUESTION: 
  . Find the most popular category (by revenue) for each active segment.
     <em>Hint</em>: The current (most up to date) active segment is specified by <code>active_flag = 'Y'</code> column in the segments table.
     Here is the some sample output:</p>
  
  <pre><code>seg_name    category    revenue
  INFREQUENT  Women       20264
  </code></pre>
  
  <p>MY ANSWER: </p>
  
  <pre><code> SELECT s.seg_name, p.category, SUM(t.item_price) revenue
  FROM segments s
  JOIN transactions t
  ON s.cust_id = t.cust_id
  JOIN products p
  ON p.prod_id = t.prod_id
  WHERE s.active_flag = 'Y'
  GROUP BY p.category
  ORDER BY revenue DESC
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0tTPQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0tTPQ.png" alt="This is the output I am getting"></a></p>
  
  <p>Is this the correct query? Thanks in advance</p>