Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL subtract two similar rows and multiply results by another row
    primarykey
    data
    text
    <p>I want to be able to subtract the qty of ondemand to reserved from the same zone, type and os and then multiply the remaining qty by the rate. </p> <p>Here is a sample dump of the mysql data </p> <pre><code>| Zone | Type | Qty | OS | Reservation | Rate | | zone1 | type1 | 12 | linux | ondemand | 0.24 | | zone1 | type1 | 6 | linux | reserved | 0.056 | | zone1 | type2 | 3 | linux | ondemand | 0.82 | | zone2 | type1 | 5 | mswin | ondemand | 0.24 | | zone2 | type1 | 2 | mswin | reserved | 0.056 | | zone2 | type2 | 3 | linux | ondemand | 0.82 | | zone3 | type1 | 4 | linux | ondemand | 0.24 | | zone3 | type1 | 1 | linux | reserved | 0.056 | </code></pre> <p>The result would be </p> <pre><code>| Zone | Type | Qty | OS | Reservation | Rate | sum() | | zone1 | type1 | 6 | linux | ondemand | 0.24 | 1.44 | | zone1 | type1 | 6 | linux | reserved | 0.056 | 0.336 | | zone1 | type2 | 3 | linux | ondemand | 0.82 | 0.246 | | zone2 | type1 | 3 | mswin | ondemand | 0.24 | 0.72 | | zone2 | type1 | 2 | mswin | reserved | 0.056 | 0.112 | | zone2 | type2 | 3 | linux | ondemand | 0.82 | 0.246 | | zone3 | type1 | 3 | linux | ondemand | 0.24 | 0.72 | | zone3 | type1 | 1 | linux | reserved | 0.056 | 0.056 | </code></pre> <p>I am not sure how to get a distinct statement to work with this. I don't know if this is possible with mysql or if I would need to script it and then produce the output. Any help is appreciated. </p> <p>There isn't always a corresponding reserved in the zone for a type and os that contains an ondemand. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload