-1

I can not programmed, the result must be ORDER BY numbers and years. Every year the numbers go over again, first we need to be shown the current year with the numbers aligned. Below comes the previous year with arranged numbers and so on.

Any idea

Thank you

SELECT k.ID, k.name, k.lastname,  k.number, YEAR(k.year),
      (k.prices + IFNULL(z.prices, 0) ) as cijena, ( (k.prices + IFNULL(z.prices, 0)) - IFNULL(u.prices, 0) ) as dug, IFNULL(z.prices, 0) as iznos from

( select ID, name, lastname, prices, year, number, from user group by ID) as u
left join (select sum(prices) as prices, ID1 from uplate group by ID1) as u
    on u.ID1 = k.ID 
left join (select sum(prices) as prices, IDk from zaduzenje group by IDk) as z
    on z.IDk = k.ID

GROUP BY  k.ID
  • Do you see how EDDY helped his audience in this http://stackoverflow.com/q/37940132 ... showing desired output, a few visuals, well I recommend you do that. Someday you might even give a sqlfiddle to us so we don't have to hand type the test data in – Drew Sep 10 '16 at 20:49

1 Answers1

0

Problem solved

SELECT k.ID, k.name, k.lastname,  k.number, YEAR(k.year),
      (k.prices + IFNULL(z.prices, 0) ) as cijena, ( (k.prices + IFNULL(z.prices, 0)) - IFNULL(u.prices, 0) ) as dug, IFNULL(z.prices, 0) as iznos from

( select ID, name, lastname, prices, year, number, from user group by ID) as k
left join (select sum(prices) as prices, ID1 from uplate group by ID1) as u
    on u.ID1 = k.ID 
left join (select sum(prices) as prices, IDk from zaduzenje group by IDk) as z
    on z.IDk = k.ID

GROUP BY  k.ID
ORDER BY YEAR(k.year) DESC, k.number DESC