Sum a value based on a row and divide that value by column












0















I need help for sum(values) base on rows.



so i have data like this



enter image description here



and i want sum based on rows so like this



enter image description here



after that i want to divide the data based on sum(rows)



so for no 1[harga] will be like this (results = 1 / 4.6),etc
maybe someone can help me?



<table class="table table-bordered">
<tr>
<th>No</th>
<th>Alternatif</th>
<?php
$dd = $this->Mymod->ViewData('kriteria');
foreach($dd as $i):
?>
<th><?= $i['kriteria_nama']; ?></th>
<?php endforeach; ?>
</tr>
<?php
$gc= $this->db->query("SELECT * from alternatif")->result_array();
$dbobot=array();
$no=0;
foreach ($gc as $cc):
$no++;
?>
<tr>
<td><?= $no; ?></td>
<td><?= $cc['alternatif_nama']; ?></td>
<?php
$de= $this->db->query("SELECT * from nilai where alternatif_kode = '$cc[alternatif_kode]'")->result_array();
foreach ($de as $cdd):
$ef= $this->db->query("SELECT max(nilai_nilai) as maxNilaiK from nilai where kriteria_kode = '$cdd[kriteria_kode]'")->row_array();
$Mnormal = $cdd['nilai_nilai'] / $ef['maxNilaiK']
?>
<td><?= $Mnormal; ?></td>
<?php
endforeach; ?>
</tr>
<?php
endforeach;
?>
</table>


update : so based on my images i have table. on my table contain No, ALternatif, Harga, Kapasitas, Luas, Jenis, Fasilitas, Jarak. And every rows has data.



1. arrayGedungA ([1],   [0.25], [1],   [0.4], [0.25], [1]);
2. arrayGedungB ([0.4], [1], [0.4], [1], [1], [0.8]);
3. arrayGedungC ([0.2], [1], [0.4], [1], [0.5], [0.8]);
4. arrayGedungD ([0.4], [1], [0.8], [1], [1], [0.4]);
5. arrayGedungE ([1], [1], [0.8], [0.2], [0.5], [0.8]);
6. arrayGedungF ([0.8], [1], [0.4], [1], [0.5], [0.8]);
7. arrayGedungG ([0.8], [0.5], [0.4], [1], [0.5], [0.2]);


my questions is




  1. i want to sum harga,kapasitas,luas,jenis,fasilitas, and jarak from top to bottom.


so data will be like this



Harga = (1 + 0.4 + 0.2 + 0.4 + 1 + 0.8 + 0.8) is 4.6
Kapasitas = (0.25 + 1 + 1 + 1 + 1 + 1 + 0.5) is 5.75
Luas = (1 + 0.4 + 0.4 + 0.8 + 0.8 + 0.4 + 0.4) is 4.2
Jenis = (0.4 + 1 + 1 + 1 + 0.2 + 1 + 1) is 5.6
Fasilitas = (0.25 + 1 + 0.5 + 1 + 0.5 + 0.5 + 0.5) is 4.25
Jarak = (1 + 0.8 + 0.8 + 0.4 + 0.8 + 0.8 + 0.2 ) is 4.8


after we have sum(rows) we need to divide them.
so will be like this



1. arrayGedungA ([1/4.6],   [0.25/5.75], [1/4.2],   [0.4/5.6], [0.25/4.25], [1/4.8]);
2. arrayGedungB ([0.4/4.6], [1/5.75], [0.4/4.2], [1/5.6], [1/4.25], [0.8/4.8]);
3. arrayGedungC ([0.2/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
4. arrayGedungD ([0.4/4.6], [1/5.75], [0.8/4.2], [1/5.6], [1/4.25], [0.4/4.8]);
5. arrayGedungE ([1/4.6], [1/5.75], [0.8/4.2], [0.2/5.6], [0.5/4.25], [0.8/4.8]);
6. arrayGedungF ([0.8/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
7. arrayGedungG ([0.8/4.6], [0.5/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.2/4.8]);


and results will be



a










share|improve this question

























  • Are you saying you want to do 1 divided by the column totals? Or are you strictly trying to sum?

    – nerdlyist
    Jan 2 at 19:09











  • i have harga, kapasitas, luas, etc. before divide, i want to sum total harga, kapasitas, luas, etc after that i want to divide them. ex. as you can see on harga we can se [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] and for total we have [4.6], so the results will be [0.2173, 0.0869, 0.0869, ..etc] . so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] = [0.2173, 0.0869, 0.0869, ..etc]

    – Rizal Terris Elvalino
    Jan 2 at 20:13











  • so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] per your comment is 4.6/4.6 which is 1. I am trying to follow your problem but I cannot tell what math you need done.

    – nerdlyist
    Jan 2 at 20:19











  • What OP wants is a ratio of each value to the sum of the whole set, I presume.

    – Dharman
    Jan 2 at 20:20













  • Something like SELECT harga/SUM(harga) FROM ...

    – Dharman
    Jan 2 at 20:21


















0















I need help for sum(values) base on rows.



so i have data like this



enter image description here



and i want sum based on rows so like this



enter image description here



after that i want to divide the data based on sum(rows)



so for no 1[harga] will be like this (results = 1 / 4.6),etc
maybe someone can help me?



<table class="table table-bordered">
<tr>
<th>No</th>
<th>Alternatif</th>
<?php
$dd = $this->Mymod->ViewData('kriteria');
foreach($dd as $i):
?>
<th><?= $i['kriteria_nama']; ?></th>
<?php endforeach; ?>
</tr>
<?php
$gc= $this->db->query("SELECT * from alternatif")->result_array();
$dbobot=array();
$no=0;
foreach ($gc as $cc):
$no++;
?>
<tr>
<td><?= $no; ?></td>
<td><?= $cc['alternatif_nama']; ?></td>
<?php
$de= $this->db->query("SELECT * from nilai where alternatif_kode = '$cc[alternatif_kode]'")->result_array();
foreach ($de as $cdd):
$ef= $this->db->query("SELECT max(nilai_nilai) as maxNilaiK from nilai where kriteria_kode = '$cdd[kriteria_kode]'")->row_array();
$Mnormal = $cdd['nilai_nilai'] / $ef['maxNilaiK']
?>
<td><?= $Mnormal; ?></td>
<?php
endforeach; ?>
</tr>
<?php
endforeach;
?>
</table>


update : so based on my images i have table. on my table contain No, ALternatif, Harga, Kapasitas, Luas, Jenis, Fasilitas, Jarak. And every rows has data.



1. arrayGedungA ([1],   [0.25], [1],   [0.4], [0.25], [1]);
2. arrayGedungB ([0.4], [1], [0.4], [1], [1], [0.8]);
3. arrayGedungC ([0.2], [1], [0.4], [1], [0.5], [0.8]);
4. arrayGedungD ([0.4], [1], [0.8], [1], [1], [0.4]);
5. arrayGedungE ([1], [1], [0.8], [0.2], [0.5], [0.8]);
6. arrayGedungF ([0.8], [1], [0.4], [1], [0.5], [0.8]);
7. arrayGedungG ([0.8], [0.5], [0.4], [1], [0.5], [0.2]);


my questions is




  1. i want to sum harga,kapasitas,luas,jenis,fasilitas, and jarak from top to bottom.


so data will be like this



Harga = (1 + 0.4 + 0.2 + 0.4 + 1 + 0.8 + 0.8) is 4.6
Kapasitas = (0.25 + 1 + 1 + 1 + 1 + 1 + 0.5) is 5.75
Luas = (1 + 0.4 + 0.4 + 0.8 + 0.8 + 0.4 + 0.4) is 4.2
Jenis = (0.4 + 1 + 1 + 1 + 0.2 + 1 + 1) is 5.6
Fasilitas = (0.25 + 1 + 0.5 + 1 + 0.5 + 0.5 + 0.5) is 4.25
Jarak = (1 + 0.8 + 0.8 + 0.4 + 0.8 + 0.8 + 0.2 ) is 4.8


after we have sum(rows) we need to divide them.
so will be like this



1. arrayGedungA ([1/4.6],   [0.25/5.75], [1/4.2],   [0.4/5.6], [0.25/4.25], [1/4.8]);
2. arrayGedungB ([0.4/4.6], [1/5.75], [0.4/4.2], [1/5.6], [1/4.25], [0.8/4.8]);
3. arrayGedungC ([0.2/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
4. arrayGedungD ([0.4/4.6], [1/5.75], [0.8/4.2], [1/5.6], [1/4.25], [0.4/4.8]);
5. arrayGedungE ([1/4.6], [1/5.75], [0.8/4.2], [0.2/5.6], [0.5/4.25], [0.8/4.8]);
6. arrayGedungF ([0.8/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
7. arrayGedungG ([0.8/4.6], [0.5/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.2/4.8]);


and results will be



a










share|improve this question

























  • Are you saying you want to do 1 divided by the column totals? Or are you strictly trying to sum?

    – nerdlyist
    Jan 2 at 19:09











  • i have harga, kapasitas, luas, etc. before divide, i want to sum total harga, kapasitas, luas, etc after that i want to divide them. ex. as you can see on harga we can se [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] and for total we have [4.6], so the results will be [0.2173, 0.0869, 0.0869, ..etc] . so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] = [0.2173, 0.0869, 0.0869, ..etc]

    – Rizal Terris Elvalino
    Jan 2 at 20:13











  • so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] per your comment is 4.6/4.6 which is 1. I am trying to follow your problem but I cannot tell what math you need done.

    – nerdlyist
    Jan 2 at 20:19











  • What OP wants is a ratio of each value to the sum of the whole set, I presume.

    – Dharman
    Jan 2 at 20:20













  • Something like SELECT harga/SUM(harga) FROM ...

    – Dharman
    Jan 2 at 20:21
















0












0








0








I need help for sum(values) base on rows.



so i have data like this



enter image description here



and i want sum based on rows so like this



enter image description here



after that i want to divide the data based on sum(rows)



so for no 1[harga] will be like this (results = 1 / 4.6),etc
maybe someone can help me?



<table class="table table-bordered">
<tr>
<th>No</th>
<th>Alternatif</th>
<?php
$dd = $this->Mymod->ViewData('kriteria');
foreach($dd as $i):
?>
<th><?= $i['kriteria_nama']; ?></th>
<?php endforeach; ?>
</tr>
<?php
$gc= $this->db->query("SELECT * from alternatif")->result_array();
$dbobot=array();
$no=0;
foreach ($gc as $cc):
$no++;
?>
<tr>
<td><?= $no; ?></td>
<td><?= $cc['alternatif_nama']; ?></td>
<?php
$de= $this->db->query("SELECT * from nilai where alternatif_kode = '$cc[alternatif_kode]'")->result_array();
foreach ($de as $cdd):
$ef= $this->db->query("SELECT max(nilai_nilai) as maxNilaiK from nilai where kriteria_kode = '$cdd[kriteria_kode]'")->row_array();
$Mnormal = $cdd['nilai_nilai'] / $ef['maxNilaiK']
?>
<td><?= $Mnormal; ?></td>
<?php
endforeach; ?>
</tr>
<?php
endforeach;
?>
</table>


update : so based on my images i have table. on my table contain No, ALternatif, Harga, Kapasitas, Luas, Jenis, Fasilitas, Jarak. And every rows has data.



1. arrayGedungA ([1],   [0.25], [1],   [0.4], [0.25], [1]);
2. arrayGedungB ([0.4], [1], [0.4], [1], [1], [0.8]);
3. arrayGedungC ([0.2], [1], [0.4], [1], [0.5], [0.8]);
4. arrayGedungD ([0.4], [1], [0.8], [1], [1], [0.4]);
5. arrayGedungE ([1], [1], [0.8], [0.2], [0.5], [0.8]);
6. arrayGedungF ([0.8], [1], [0.4], [1], [0.5], [0.8]);
7. arrayGedungG ([0.8], [0.5], [0.4], [1], [0.5], [0.2]);


my questions is




  1. i want to sum harga,kapasitas,luas,jenis,fasilitas, and jarak from top to bottom.


so data will be like this



Harga = (1 + 0.4 + 0.2 + 0.4 + 1 + 0.8 + 0.8) is 4.6
Kapasitas = (0.25 + 1 + 1 + 1 + 1 + 1 + 0.5) is 5.75
Luas = (1 + 0.4 + 0.4 + 0.8 + 0.8 + 0.4 + 0.4) is 4.2
Jenis = (0.4 + 1 + 1 + 1 + 0.2 + 1 + 1) is 5.6
Fasilitas = (0.25 + 1 + 0.5 + 1 + 0.5 + 0.5 + 0.5) is 4.25
Jarak = (1 + 0.8 + 0.8 + 0.4 + 0.8 + 0.8 + 0.2 ) is 4.8


after we have sum(rows) we need to divide them.
so will be like this



1. arrayGedungA ([1/4.6],   [0.25/5.75], [1/4.2],   [0.4/5.6], [0.25/4.25], [1/4.8]);
2. arrayGedungB ([0.4/4.6], [1/5.75], [0.4/4.2], [1/5.6], [1/4.25], [0.8/4.8]);
3. arrayGedungC ([0.2/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
4. arrayGedungD ([0.4/4.6], [1/5.75], [0.8/4.2], [1/5.6], [1/4.25], [0.4/4.8]);
5. arrayGedungE ([1/4.6], [1/5.75], [0.8/4.2], [0.2/5.6], [0.5/4.25], [0.8/4.8]);
6. arrayGedungF ([0.8/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
7. arrayGedungG ([0.8/4.6], [0.5/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.2/4.8]);


and results will be



a










share|improve this question
















I need help for sum(values) base on rows.



so i have data like this



enter image description here



and i want sum based on rows so like this



enter image description here



after that i want to divide the data based on sum(rows)



so for no 1[harga] will be like this (results = 1 / 4.6),etc
maybe someone can help me?



<table class="table table-bordered">
<tr>
<th>No</th>
<th>Alternatif</th>
<?php
$dd = $this->Mymod->ViewData('kriteria');
foreach($dd as $i):
?>
<th><?= $i['kriteria_nama']; ?></th>
<?php endforeach; ?>
</tr>
<?php
$gc= $this->db->query("SELECT * from alternatif")->result_array();
$dbobot=array();
$no=0;
foreach ($gc as $cc):
$no++;
?>
<tr>
<td><?= $no; ?></td>
<td><?= $cc['alternatif_nama']; ?></td>
<?php
$de= $this->db->query("SELECT * from nilai where alternatif_kode = '$cc[alternatif_kode]'")->result_array();
foreach ($de as $cdd):
$ef= $this->db->query("SELECT max(nilai_nilai) as maxNilaiK from nilai where kriteria_kode = '$cdd[kriteria_kode]'")->row_array();
$Mnormal = $cdd['nilai_nilai'] / $ef['maxNilaiK']
?>
<td><?= $Mnormal; ?></td>
<?php
endforeach; ?>
</tr>
<?php
endforeach;
?>
</table>


update : so based on my images i have table. on my table contain No, ALternatif, Harga, Kapasitas, Luas, Jenis, Fasilitas, Jarak. And every rows has data.



1. arrayGedungA ([1],   [0.25], [1],   [0.4], [0.25], [1]);
2. arrayGedungB ([0.4], [1], [0.4], [1], [1], [0.8]);
3. arrayGedungC ([0.2], [1], [0.4], [1], [0.5], [0.8]);
4. arrayGedungD ([0.4], [1], [0.8], [1], [1], [0.4]);
5. arrayGedungE ([1], [1], [0.8], [0.2], [0.5], [0.8]);
6. arrayGedungF ([0.8], [1], [0.4], [1], [0.5], [0.8]);
7. arrayGedungG ([0.8], [0.5], [0.4], [1], [0.5], [0.2]);


my questions is




  1. i want to sum harga,kapasitas,luas,jenis,fasilitas, and jarak from top to bottom.


so data will be like this



Harga = (1 + 0.4 + 0.2 + 0.4 + 1 + 0.8 + 0.8) is 4.6
Kapasitas = (0.25 + 1 + 1 + 1 + 1 + 1 + 0.5) is 5.75
Luas = (1 + 0.4 + 0.4 + 0.8 + 0.8 + 0.4 + 0.4) is 4.2
Jenis = (0.4 + 1 + 1 + 1 + 0.2 + 1 + 1) is 5.6
Fasilitas = (0.25 + 1 + 0.5 + 1 + 0.5 + 0.5 + 0.5) is 4.25
Jarak = (1 + 0.8 + 0.8 + 0.4 + 0.8 + 0.8 + 0.2 ) is 4.8


after we have sum(rows) we need to divide them.
so will be like this



1. arrayGedungA ([1/4.6],   [0.25/5.75], [1/4.2],   [0.4/5.6], [0.25/4.25], [1/4.8]);
2. arrayGedungB ([0.4/4.6], [1/5.75], [0.4/4.2], [1/5.6], [1/4.25], [0.8/4.8]);
3. arrayGedungC ([0.2/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
4. arrayGedungD ([0.4/4.6], [1/5.75], [0.8/4.2], [1/5.6], [1/4.25], [0.4/4.8]);
5. arrayGedungE ([1/4.6], [1/5.75], [0.8/4.2], [0.2/5.6], [0.5/4.25], [0.8/4.8]);
6. arrayGedungF ([0.8/4.6], [1/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.8/4.8]);
7. arrayGedungG ([0.8/4.6], [0.5/5.75], [0.4/4.2], [1/5.6], [0.5/4.25], [0.2/4.8]);


and results will be



a







php database sum






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 22:04







Rizal Terris Elvalino

















asked Jan 2 at 18:13









Rizal Terris ElvalinoRizal Terris Elvalino

206




206













  • Are you saying you want to do 1 divided by the column totals? Or are you strictly trying to sum?

    – nerdlyist
    Jan 2 at 19:09











  • i have harga, kapasitas, luas, etc. before divide, i want to sum total harga, kapasitas, luas, etc after that i want to divide them. ex. as you can see on harga we can se [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] and for total we have [4.6], so the results will be [0.2173, 0.0869, 0.0869, ..etc] . so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] = [0.2173, 0.0869, 0.0869, ..etc]

    – Rizal Terris Elvalino
    Jan 2 at 20:13











  • so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] per your comment is 4.6/4.6 which is 1. I am trying to follow your problem but I cannot tell what math you need done.

    – nerdlyist
    Jan 2 at 20:19











  • What OP wants is a ratio of each value to the sum of the whole set, I presume.

    – Dharman
    Jan 2 at 20:20













  • Something like SELECT harga/SUM(harga) FROM ...

    – Dharman
    Jan 2 at 20:21





















  • Are you saying you want to do 1 divided by the column totals? Or are you strictly trying to sum?

    – nerdlyist
    Jan 2 at 19:09











  • i have harga, kapasitas, luas, etc. before divide, i want to sum total harga, kapasitas, luas, etc after that i want to divide them. ex. as you can see on harga we can se [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] and for total we have [4.6], so the results will be [0.2173, 0.0869, 0.0869, ..etc] . so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] = [0.2173, 0.0869, 0.0869, ..etc]

    – Rizal Terris Elvalino
    Jan 2 at 20:13











  • so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] per your comment is 4.6/4.6 which is 1. I am trying to follow your problem but I cannot tell what math you need done.

    – nerdlyist
    Jan 2 at 20:19











  • What OP wants is a ratio of each value to the sum of the whole set, I presume.

    – Dharman
    Jan 2 at 20:20













  • Something like SELECT harga/SUM(harga) FROM ...

    – Dharman
    Jan 2 at 20:21



















Are you saying you want to do 1 divided by the column totals? Or are you strictly trying to sum?

– nerdlyist
Jan 2 at 19:09





Are you saying you want to do 1 divided by the column totals? Or are you strictly trying to sum?

– nerdlyist
Jan 2 at 19:09













i have harga, kapasitas, luas, etc. before divide, i want to sum total harga, kapasitas, luas, etc after that i want to divide them. ex. as you can see on harga we can se [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] and for total we have [4.6], so the results will be [0.2173, 0.0869, 0.0869, ..etc] . so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] = [0.2173, 0.0869, 0.0869, ..etc]

– Rizal Terris Elvalino
Jan 2 at 20:13





i have harga, kapasitas, luas, etc. before divide, i want to sum total harga, kapasitas, luas, etc after that i want to divide them. ex. as you can see on harga we can se [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] and for total we have [4.6], so the results will be [0.2173, 0.0869, 0.0869, ..etc] . so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] = [0.2173, 0.0869, 0.0869, ..etc]

– Rizal Terris Elvalino
Jan 2 at 20:13













so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] per your comment is 4.6/4.6 which is 1. I am trying to follow your problem but I cannot tell what math you need done.

– nerdlyist
Jan 2 at 20:19





so [1, 0.4, 0.2, 0.4, 1, 0.8, 0.8] / [4.6] per your comment is 4.6/4.6 which is 1. I am trying to follow your problem but I cannot tell what math you need done.

– nerdlyist
Jan 2 at 20:19













What OP wants is a ratio of each value to the sum of the whole set, I presume.

– Dharman
Jan 2 at 20:20







What OP wants is a ratio of each value to the sum of the whole set, I presume.

– Dharman
Jan 2 at 20:20















Something like SELECT harga/SUM(harga) FROM ...

– Dharman
Jan 2 at 20:21







Something like SELECT harga/SUM(harga) FROM ...

– Dharman
Jan 2 at 20:21














1 Answer
1






active

oldest

votes


















0














Depending on database (and using the suggestion by Dharman) this works on Oracle:



SELECT harga,
harga / SUM (harga) OVER () harga_sum,
kapasitas,
kapasitas / SUM (kapasitas) OVER () kapasitas_sum
FROM nilai
WHERE ...


Note that the OVER() has to be given after each SUM(...) and before aliased column names.






share|improve this answer
























  • You haven't improved much upon my comment... I would suggest to add the optional AS to make the aliasing clearer.

    – Dharman
    Jan 2 at 21:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011198%2fsum-a-value-based-on-a-row-and-divide-that-value-by-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Depending on database (and using the suggestion by Dharman) this works on Oracle:



SELECT harga,
harga / SUM (harga) OVER () harga_sum,
kapasitas,
kapasitas / SUM (kapasitas) OVER () kapasitas_sum
FROM nilai
WHERE ...


Note that the OVER() has to be given after each SUM(...) and before aliased column names.






share|improve this answer
























  • You haven't improved much upon my comment... I would suggest to add the optional AS to make the aliasing clearer.

    – Dharman
    Jan 2 at 21:09
















0














Depending on database (and using the suggestion by Dharman) this works on Oracle:



SELECT harga,
harga / SUM (harga) OVER () harga_sum,
kapasitas,
kapasitas / SUM (kapasitas) OVER () kapasitas_sum
FROM nilai
WHERE ...


Note that the OVER() has to be given after each SUM(...) and before aliased column names.






share|improve this answer
























  • You haven't improved much upon my comment... I would suggest to add the optional AS to make the aliasing clearer.

    – Dharman
    Jan 2 at 21:09














0












0








0







Depending on database (and using the suggestion by Dharman) this works on Oracle:



SELECT harga,
harga / SUM (harga) OVER () harga_sum,
kapasitas,
kapasitas / SUM (kapasitas) OVER () kapasitas_sum
FROM nilai
WHERE ...


Note that the OVER() has to be given after each SUM(...) and before aliased column names.






share|improve this answer













Depending on database (and using the suggestion by Dharman) this works on Oracle:



SELECT harga,
harga / SUM (harga) OVER () harga_sum,
kapasitas,
kapasitas / SUM (kapasitas) OVER () kapasitas_sum
FROM nilai
WHERE ...


Note that the OVER() has to be given after each SUM(...) and before aliased column names.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 21:04









LGonyerLGonyer

215




215













  • You haven't improved much upon my comment... I would suggest to add the optional AS to make the aliasing clearer.

    – Dharman
    Jan 2 at 21:09



















  • You haven't improved much upon my comment... I would suggest to add the optional AS to make the aliasing clearer.

    – Dharman
    Jan 2 at 21:09

















You haven't improved much upon my comment... I would suggest to add the optional AS to make the aliasing clearer.

– Dharman
Jan 2 at 21:09





You haven't improved much upon my comment... I would suggest to add the optional AS to make the aliasing clearer.

– Dharman
Jan 2 at 21:09




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011198%2fsum-a-value-based-on-a-row-and-divide-that-value-by-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas