title: Group by with extra features MySQL
body: <p>I'm trying to get sum for all Key For all years(separate) there is more than one in each year, and takeng information from three DB
  I can do it for one year, but how to do it from all. There ara actually two years 1996 and 1997</p>
  
  <p>This is how to get everything for 1996 and almost the same how to get for 1997
  But how to join them orr get everithing correctly </p>
  
  <pre><code>SELECT OrderID, CustomerID, OrderDate, sum(Cost) as TotalCost
  FROM (SELECT Orders.CustomerID, Orders.OrderID, Orders.OrderDate, Orders.OrderID, OrderDetails.ProductID, (OrderDetails.Quantity* Products.Price) as Cost
               FROM Orders, OrderDetails, Products
               WHERE Orders.OrderID = OrderDetails.OrderID
               AND OrderDetails.ProductID= Products.ProductID)
  WHERE OrderDate&lt;="1996-12-31"
  Group by CustomerID
  </code></pre>
  
  <p>here is tables what I have 
  Orders</p>
  
  <pre><code>+---------+------------+------------+------------+-----------+
  | OrderID | CustomerID | EmployeeID | OrderDate  | ShipperID |
  +---------+------------+------------+------------+-----------+
  |   10248 |         90 |          5 | 1996-07-04 |         3 |
  |   10249 |         81 |          6 | 1996-07-05 |         1 |
  |   10250 |         34 |          4 | 1996-07-08 |         2 |
  |   10251 |         84 |          3 | 1997-07-08 |         1 |
  |   10252 |         76 |          4 | 1997-07-09 |         2 |
  +---------+------------+------------+------------+-----------+
  </code></pre>
  
  <p>OrderDetails</p>
  
  <pre><code>+---------------+---------+-----------+----------+
  | OrderDetailID | OrderID | ProductID | Quantity |
  +---------------+---------+-----------+----------+
  |             1 |   10248 |        1 |       12 |
  |             2 |   10248 |        2 |       10 |
  |             3 |   10248 |        3 |        5 |
  |             4 |   10249 |        1 |        9 |
  |             5 |   10249 |        2 |       40 |
  |             6 |   10250 |        1 |       10 |
  |             7 |   10250 |        2 |       35 |
  |             8 |   10250 |        3 |       15 |
  +---------------+---------+-----------+----------+
  </code></pre>
  
  <p>and Products</p>
  
  <pre><code>+-----------+--+------------+------------+--+-------+
  | ProductID |  | SupplierID | CategoryID |  | Price |
  +-----------+--+------------+------------+--+-------+
  |         1 |  |          1 |          1 |  |    18 |
  |         2 |  |          1 |          1 |  |    19 |
  |         3 |  |          1 |          2 |  |    10 |
  +-----------+--+------------+------------+--+-------+
  </code></pre>
  
  <p>I Use MySQL
  Sorry for long post</p>
  
  <p>P.S. it said </p>
  
  <blockquote>
    <p>no such function: year</p>
  </blockquote>
  
  <p>P.P.S. I used to use SQLlite</p>