Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like:</p> <pre><code>SELECT [Customers].Customer_ID , COUNT(*) AS NumOrders FROM [Customers] INNER JOIN [Orders] ON [Orders].Customer_ID = [Customers].Customer_ID WHERE ([Customers].Gender = 'Female') GROUP BY [Customers].Customer_ID; </code></pre> <hr> <p>The <code>INNER JOIN</code> should be changed into <code>LEFT JOIN</code> <strong>to include Customers without any Orders</strong> (and <code>COUNT(*)</code> should be changed to <code>COUNT(Orders.Customer_ID)</code> as @onedaywhen spotted):</p> <pre><code>SELECT [Customers].Customer_ID , COUNT(Orders.Customer_ID) AS NumOrders FROM [Customers] LEFT JOIN [Orders] ON [Orders].Customer_ID = [Customers].Customer_ID WHERE ([Customers].Gender = 'Female') GROUP BY [Customers].Customer_ID; </code></pre> <p><strong>Note</strong>, that the above queries will give you <strong>number of Orders</strong> and not number of <strong>Products</strong> as you describe. You'll have to provide the structure of the tables (probably <code>Orders</code>, or <code>OrderDetails</code> if you have such a table) so we know where the information about products (and their orders) is stored.</p> <hr> <hr> <p>Sidenote: as (again, deserving more than half of these points :) @onedaywhen spotted, the <code>Customer_ID</code> is supposed to be the <code>PRIMARY KEY</code> of table <code>[Customers]</code>. If that's the case (or if it is <code>UNIQUE</code>), your original query could be simplified:</p> <pre><code>SELECT [Customers].Customer_ID FROM [Customers] WHERE [Customers].Gender = 'Female' ; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload