I want to ask about a pivot table to join another table. Its appearance is as follows:
Result
| DATE | A | B | C | D |
|-----------|---|----|----|----|
|2015-06-01 |10 | 20 | 30 | 20 |
|2015-06-02 |20 | 30 | 40 | 20 |
|2015-06-03 |40 | 10 | 10 | 20 |
This table is taken from the following two tables:
Table wizard
|ID|Type|
|--|----|
|1 |A |
|2 |B |
|3 |C |
Table type
|ID|Date | idType |value|
|--|----------|--------|-----|
|1 |2015-06-01| 1 | 10 |
|2 |2015-06-01| 2 | 20 |
|3 |2015-06-01| 3 | 30 |
|4 |2015-06-01| 4 | 20 |
|5 |2015-06-02| 1 | 20 |
|6 |2015-06-02| 2 | 30 |
|7 |2015-06-02| 3 | 40 |
|8 |2015-06-02| 4 | 20 |
|9 |2015-06-03| 1 | 40 |
|10|2015-06-03| 2 | 10 |
|11|2015-06-03| 3 | 10 |
|12|2015-06-03| 4 | 20 |
I tried this code below but it failed.
SELECT * FROM ( SELECT tgl_nab, idtype, nilai FROM jts_test ) src pivot (sum(nilai) for idtype in ([1], [2], [3],[4]) ) piv;
The error is displayed as follows:
You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near 'pivot (sum (nilai) for idtype in ([1], [2], [3], [4])) piv LIMIT 0, 25' in line 1
And I have another related question. How to show a table of results in a codeigniter view. Let's say I have a controller to select all the data, like this code below:
public function test()
{
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['test'] = $this->report_m->get_allcontentest();
$this->load->view('header');
$this->load->view('report/test_list_view',$data);
$this->load->view('footer');
} else {
redirect('login');
}
}
, , , . , , .
, , . , .
<div class="box-body table-responsive">
<table id="datatable" class="table table-bordered table-hover">
<thead>
<tr>
<th>No</th>
<th><?php echo $baris->type; ?></th>
<th>Created At</th>
<th>Menu</th>
</tr>
</thead>
<tbody>
<?php
foreach($report as $baris){
?>
<tr>
<td><?php echo $baris->id; ?></td>
<td><?php echo $baris->nilai; ?></td>
<td><?php echo $baris->create; ?></td>
<td>
<a href="#" class="fa fa-eye"></a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
appriciete .