Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've written some SQL to get the results you want here: <a href="http://www.sqlfiddle.com/#!2/1a54a/1" rel="nofollow">http://www.sqlfiddle.com/#!2/1a54a/1</a></p> <p>The following is the code. I'm not sure how well this would perform but you could try it:</p> <pre><code>SET @bbinSize = 0.1; SET @lbinSize = 0.1; SET @kbinSize = 1; SELECT bbin, lbin, kbin, COUNT(*) FROM ( SELECT a.b, a.l, a.k_1AperMag1, ((FLOOR(((1 / @bbinSize) * a.b)) * @bbinSize) + @bbinSize / 2) bbin, ((FLOOR(((1 / @lbinSize) * a.l)) * @lbinSize) + @lbinSize / 2) lbin, ((FLOOR(((1 / @kbinSize) * a.k_1AperMag1)) * @kbinSize) + @kbinSize / 2) kbin FROM MyTable a ) bins GROUP BY bbin, lbin, kbin </code></pre> <p>What might be a better idea would be to create three new tables, <code>BBin</code>, <code>LBin</code> and <code>KBin</code> each of which contain three columns <code>Name</code>, <code>MinValue</code>, <code>MaxValue</code>. Then you populate each bin into these.</p> <p>Your query could then become something like:</p> <pre><code>SELECT BBin.Name, LBin.Name, KBin.Name COUNT(*) as MyCount FROM MyTable LEFT JOIN BBin ON MyTable.B &gt;= BBin.MinValue AND MyTable.B &lt; BBin.MaxValue LEFT JOIN LBin ON MyTable.L &gt;= LBin.MinValue AND MyTable.L &lt; LBin.MaxValue LEFT JOIN KBin ON MyTable.KAperMag1 &gt;= KBin.MinValue AND MyTable.KAperMag1 &lt; KBin.MaxValue GROUP BY BBin.Name LBin.Name KBin.Name </code></pre> <p>I'd suspect the second option would perform better but I'll leave that to you to test.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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