These are chat archives for eysteinn13/FraunhoferDBWebsite

29th
Jun 2015
Eysteinn Gunnlaugsson
@eysteinn13
Jun 29 2015 13:15
SELECT
i.id,
p.amount,
pa.amount
FROM items AS i
LEFT JOIN (SELECT
id,
item_id,
SUM(amount) amount
FROM payments
GROUP BY item_id) AS p
ON p.item_id = i.id
LEFT JOIN (SELECT
payment_id,
sUM(amount) amount
FROM payment_actions) AS pa
ON pa.payment_id = p.id
group by i.id
SELECT
  i.id,
  p.amount,
  pa.amount
FROM items AS i
  LEFT JOIN (SELECT
           id,
           item_id,
           SUM(amount)    amount
         FROM payments
         GROUP BY item_id) AS p
    ON p.item_id = i.id
  LEFT JOIN (SELECT
           payment_id,
           sUM(amount)    amount
         FROM payment_actions) AS pa
    ON pa.payment_id = p.id
group by i.id
Eysteinn Gunnlaugsson
@eysteinn13
Jun 29 2015 14:05
SELECT SUM(l.quantity), SUM(p.amount)
FROM lineitem AS l
  LEFT JOIN (SELECT lineitem_ID, discount_ID, SUM(number_of_tools) AS amount
         FROM discount
         GROUP BY lineitem_ID) AS p
    ON l.lineitem_ID = p.lineitem_ID, pos
WHERE pos.po_ID = l.po_ID
GROUP BY pos.customer_ID;