1
I have a 'point' table, with columns (id, Pis, date, time), which record the input and output of a product ('Pis'). I wanted to group in another table, where the data, Pis and date, are equal group all the data 'time' are grouped in a single column. Ex Table 1
+-------+--------------+-------------+----------+
| id | pis | data | hora |
+-------+--------------+-------------+----------+
| 1 | 12113879222 | 2018-02-02 | 07:21:00 |
| 2 | 12113879222 | 2018-02-02 | 11:59:00 |
| 3 | 21056646219 | 2018-02-02 | 07:32:00 |
| 4 | 21056646219 | 2017-05-17 | 12:01:00 |
For table 2
+-------+--------------+-------------+----------+----------+
| id | pis | data | hora1 | hora2 |
+-------+--------------+-------------+----------+----------+
| 1 | 12113879222 | 2018-02-02 | 07:21:00 | 11:59:00 |
| 3 | 21056646219 | 2018-02-02 | 07:32:00 | |
| 4 | 21056646219 | 2017-05-17 | 12:01:00 | |
I couldn’t understand what you wrote. Try to format your question and describe your problem better. Use punctuation and grammar to write and before posting read. If you understand, click Save. This way we can help you better.
– Diego Souza
Man what you want to do is something very complex, what is the need to do this? see if this link helps you https://stackoverflow.com/q/12643117
– Paulo Alexandre
Which SQL? Oracle, Mysql, Sqlserver, Postgresql?
– William John Adam Trindade
@Williamjohnadamtrindade - Mysql
– Luan Peil
@Diegosouza - I rewrote it, I think it’s clear now
– Luan Peil
Just grouping would be easy and could make a
select..into
orinsert...select
to generate the new table, but breaking the time in columns requires resources such as pivot table for example. The problem is that you don’t know how many columns of hours you will have right? That way it becomes quite impossible to do this– Ricardo Pontual
And are the hour columns dynamic? or can it be a comma-only column? Mysql Does not have a native PIVOT operator. https://modern-sql.com/use-case/pivot
– William John Adam Trindade