0

I have the following Firebird table Mytable1

<style type="text/css">
.tftable {font-size:12px;color:#333333;width:50%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
.tftable tr:hover {background-color:#ffffff;}
</style>

<table class="tftable" border="1">
<tr><th>EnrolNO</th><th>dateP</th><th>timeP</th><th>inOut</th></tr>
<tr><td>002</td><td>11/01/2020</td><td>08:12</td><td>0</td></tr>
<tr><td>002</td><td>11/01/2020</td><td>16:22</td><td>1</td></tr>
<tr><td>002</td><td>11/01/2020</td><td>17:02</td><td>0</td></tr>
<tr><td>003</td><td>11/01/2020</td><td>18:55</td><td>0</td></tr>
<tr><td>003</td><td>11/01/2020</td><td>06:19</td><td>1</td></tr>

</table>

Nb. 0 = in. 1 = out

I want to rotate the table in SQL Firebird query as follows:

<style type="text/css">
.tftable {font-size:12px;color:#333333;width:50%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
.tftable tr:hover {background-color:#ffffff;}
</style>

<table class="tftable" border="1">
<tr><th>EnrolNO</th><th>dateP</th><th>TM1</th><th>TM2</th><th>TM3</th></tr>
<tr><td>002</td><td>11/01/2020</td><td>08:12:22</td><td>16:22</td><td>17:02</td></tr>
<tr><td>003</td><td>11/01/2020</td><td>18:55</td><td>06:19</td><td>Null</td></tr>
</table>

thanks

  • Stackoverflow.com is for English questions only. – maio290 Mar 15 '20 at 23:02
  • Thanks !! I will repost it in English – ISMAIL SELLAM Mar 15 '20 at 23:06
  • Why are you posting HTML code for what is a SQL question? That feature is not intended to provide 'pretty' rendering of your data. Also, Stack Overflow has an expectation that you at least try something and provide an attempt, and clearly describe what isn't working with that attempt. – Mark Rotteveel Mar 16 '20 at 14:00
  • Pivoting is a task for client (reporting) applications, not for database servers. https://stackoverflow.com/questions/55449169 / https://stackoverflow.com/questions/29896351 / https://stackoverflow.com/questions/25822132 / https://stackoverflow.com/questions/48262968 – Arioch 'The Mar 16 '20 at 17:38
  • @ISMAILSELLAM How many TM columns does this table have? Is it variable? Or only TM1, TM2, & TM3? – Ed Mendez Mar 16 '20 at 22:16
  • The table contains variable TM1... TM2 .... TMn , i dont know the number of columns of in and out ... Thanks Ed Mendez – ISMAIL SELLAM Mar 17 '20 at 00:00
  • @ISMAILSELLAM you can read Firebird's `system tables` (read documentation on official site) to query a list of columns named `similar` to TM+number on your `relation` (table or view). Then you can dynamically hack together an ad hoc pivoting SQL query, like described in the links above. Still that would be more of abuse than a good solution. – Arioch 'The Mar 17 '20 at 09:30

0 Answers0