title: Get product sales reports from postgresql via graphql
body: <p>I have a very limited experience with databases (I'm currently learning postgres), which is why I'm asking here, what would be the &quot;industry standard&quot; way of doing / creating sales reports based on a timeframe, from a postgres db via graphQL?</p>
  <p>Why via graphQL? Because, as I said above, I'm just learning databases and don't know yet how to properly do JOINs, views, and other advanced queries.</p>
  <p>My setup on the GraphQL side is this: <code>Products -&gt; CartItems -&gt; Orders -&gt; OrderItems</code>.</p>
  <p>On <code>AddtoCart</code> each product item is transformed into a <code>CartItem</code>. Once the order is finished, the <code>Cart</code> and each <code>CartItem</code> will be saved in the database as an <code>Order</code> and as <code>OrderItem</code>.</p>
  <p>In the database I have the following:</p>
  <p><code>Product</code> - table with all products that are for sale.</p>
  <p><code>CartItem</code> - table with products that are in the Cart.</p>
  <p><code>Order</code> - table with all sales, with foreign keys to each OrderItem.</p>
  <p><code>OrderItem</code> - table with sold products.</p>
  <p>Until now I used to get the monthly sales for each product by doing two nested graphQL queries in the frontend: one query to get all products, and one nested query to get the <code>aggregate.count</code> for each product, filtering by product name, store and timeframe.</p>
  <p>Finally the question is: should I do this query at the database level using SQL? Should I create another table <code>Sales</code> and populate it with data from the other tables? If yes, what would be a good starting point, and if no, how should I continue to do this with GraphQL in javascript?</p>