Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server : queries for quantity
    primarykey
    data
    text
    <p><strong>TABLE 1</strong></p> <pre><code>ID | DATE | a | 10-07-2012 | b | 10-07-2012 | c | 10-07-2012 | </code></pre> <p><strong>TABLE2</strong></p> <pre><code>ID | OrdersID | a | 001 | b | 002 | c | 003 | </code></pre> <p><strong>TABLE3</strong></p> <pre><code>ItemID | OrdersID | Items | 1 | 001 | 5 | 2 | 002 | 3 | 7 | 003 | 2 | 3 | 003 | 7 | 4 | 001 | 8 | 2 | 003 | 7 | 5 | 003 | 6 | 6 | 003 | 1 | </code></pre> <p><strong>TABLE4</strong></p> <pre><code> ItemID | ItemName | 1 | ABC | 2 | EFG | 3 | HIJ | 4 | KLM | 5 | NOP | 6 | QRS | 7 | TUV | </code></pre> <p>I would like to select the ID's from <code>TABLE1</code> t where <code>Date = 10-07-2012</code></p> <p>In <code>Table2</code> with the ID's I would like to select the <code>OrdersID</code>'s</p> <p>With the <code>OrdersID</code>'s I would like to add together how many Items of a <code>ItemID</code> exist e.g. <code>IteamID</code> 2 has a total of 10 Items</p> <p>From <code>TABLE3</code> I would like to know the top 5 Items and the quantity of Items in Order and get the names of the the <code>ItemID</code> from <code>TABLLE4</code> <code>ItemName</code>.</p> <p>Expected results 5 results </p> <pre><code>ItemID | ItemName | Quantity | 2 | EFG | 10 | 3 | HIJ | 7 | ..... ..... ..... ..... </code></pre> <p>SQL used at the start ...</p> <pre><code> SELECT SUM (t3.Items) , t4.ItemName FROM Table3 t3 JOIN Table2 t2 ON t3.OrdersID = t2.OrdersID JOIN Table1 t1 ON t2.ID = t1.ID WHERE t1.[Date] = '10072012 00:00:00' </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. 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