T
T
tigra2016-02-12 11:14:59
MySQL
tigra, 2016-02-12 11:14:59

What should a complex select query look like?

There is data

id  |  project_id  |      name    |  type    |
________________________________________________
1   |        2     |   запрос 1   |    1     |
2   |        2     |   запрос 2   |    4     |
3   |        1     |   запрос 3   |    3     |
4   |        3     |   запрос 4   |    2     |
4   |        2     |   запрос 5   |    4     |

in the type field there can be values ​​​​1,2,3,4
you need to group by the project_id field, while (in some way unknown to me) to calculate
how many pieces in the type field with 1, 2, 3, 4
it should turn out something like that
id  |  project_id  |      name    |  type    |  type1  |  type2  |  type3  |  type4  |
______________________________________________________________________________
1   |        2     |   запрос 1   |    1     |    1    |    0    |    0    |     2    |

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2016-02-12
@tigroid3

Based on the task, it is necessary to group by two fields - project_id and type:
select project_id, type, count(*)
from tabel
group by project_id, type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question