Answer the question
In order to leave comments, you need to log in
Implement on Mysql: Selection by 2 periods (previous, current) of one contract?
Good day! I ask for your help with a query in Mysql that is difficult for me.
It is necessary to fill the table with different data for the periods.
The original table looks like this:
id | nomer | sostoyanienadatu | summa |
------------------------------------------
1 |номер 1| 2014-09-15 | 100 |
2 |номер 2| 2014-10-10 | 200 |
3 |номер 1| 2014-10-05 | 300 |
4 |номер 3| 2014-10-11 | 400 |
5 |номер 4| 2014-09-06 | 500 |
nomer | prmysyac | tekywiymesiac |
------------------------------------
номер 1 | 100 | 300 |
номер 2 | | 200 |
номер 3 | | 400 |
номер 4 | 500 | |
SELECT `nomer`,`zakazchik`, FROM database.table WHERE sostoyanienadatu LIKE '2014-09%';
SELECT * FROM database.table WHERE (nomer,sostoyanienadatu) IN (SELECT nomer, MAX(sostoyanienadatu) FROM database.table GROUP BY nomer);
Answer the question
In order to leave comments, you need to log in
On one good forum , they suggested how to do everything :)
I'll post the result here, suddenly it will come in handy for someone :)
select t.nomer, t1.`summa` prmysyac , t2.`summa` tekywiymesiac from database.table t left join
(select nomer, `summa` from database.table where month(sostoyanienadatu)=9 ) t1 using(nomer) left join
(select nomer, `summa` from database.table where month(sostoyanienadatu)=10 ) t2 using (nomer) GROUP BY nomer;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question