SQL选择每xth累积总和的行

时间:2018-07-10 17:57:21

标签: sql hive

假设我有一个看起来像这样的表:

echo "
<!DOCTYPE html>
<html>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' href='../styles/style.css'>
<body>
<header>
<h1>Dundas Agri Systems Employee Page</h1>
<h2>Always search for a Spirit of Tranquility</h2>
</header>";


echo "<div class='tab'>";
if ($_SESSION["role"]==admin || $_SESSION["role"]==tech || $_SESSION["role"]==emp){
echo "<button class=''tablinks'' onclick=''OpenFolder(event, 'Employee')'' id=''defaultOpen''>Employee</button>";
}
if ($_SESSION["role"]==admin || $_SESSION["role"]==tech){
echo "<button class=''tablinks' onclick=''openFolder(event, 'Lely')''>Lely</button>";
}
if ($_SESSION["role"]==admin){
echo "<button class='tablinks' onclick='openFolder(event, 'Manager')''>Manager</button>";
}
echo "</div>";
if ($_SESSION["role"]==admin || $_SESSION["role"]==tech){
echo "<div id='Lely' class='tabcontent'>
<div id='container'>
<h1>Directory Contents</h1>

<table class='sortable'>
  <thead>
    <tr>
      <th>Filename</th>
      <th>Type</th>
      <th>Size <small>(bytes)</small></th>
      <th>Date Modified</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
";      
openfilesystem('./LelyUploads');   
echo "   
</tbody>
</table>

<div id='Upload'>
    <form action='' method ='post' enctype='multipart/form-data'>
        Select a file to upload:
        <input type='file' name='fileToUpload' id='fileToUpload'>
        <input type='submit' value='Submit' name='submit' id='submit'>
    </form>
</div>

</div>
</div>";
}
if ($_SESSION["role"]==admin || $_SESSION["role"]==tech || $_SESSION["role"]==emp){   
echo "<div id='Employee' class='tabcontent'>
<div id='container'>

<h1>Directory Contents</h1>

<table class='sortable'>
  <thead>
    <tr>
      <th>Filename</th>
      <th>Type</th>
      <th>Size <small>(bytes)</small></th>
      <th>Date Modified</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
";
openfilesystem('./uploads');    
echo "
</tbody>
</table>

<div id='Upload'>
    <form action='' method ='post' enctype='multipart/form-data'>
        Select a file to upload:
        <input type='file' name='fileToUpload' id='fileToUpload'>
        <input type='submit' value='Submit' name='submit' id='submit'>
    </form>
</div>

</div>
</div>";
}
if ($_SESSION["role"]==admin){  
echo "<div id='Manager' class='tabcontent'>
<div id='container'>

<h1>Directory Contents</h1>

<table class='sortable'>
  <thead>
    <tr>
      <th>Filename</th>
      <th>Type</th>
      <th>Size <small>(bytes)</small></th>
      <th>Date Modified</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
";
    openfilesystem('./LelyUploads');

echo "
</tbody>
</table>

<div id='Upload'>
    <form action='' method ='post' enctype='multipart/form-data'>
        Select a file to upload:
        <input type='file' name='fileToUpload' id='fileToUpload'>
        <input type='submit' value='Submit' name='submit' id='submit'>
    </form>
</div>

</div>
</div>";
}


echo "
<script>
function openFolder(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName('tabcontent');
for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = 'none';
}
tablinks = document.getElementsByClassName('tablinks');
for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(' active', '');
}
document.getElementById(cityName).style.display = 'block';
evt.currentTarget.className += '' active';
}

// Get the element with id='defaultOpen' and click on it
// document.getElementById('defaultOpen').click();
</script>

</body>
</html>
";

我希望能够建立刚好大于或等于x的范围。例如,如果x = 10,我想设置范围1(10),2(12),3-4(10),5-6(18)。

我的第一种方法是从第一个表中构建一个累加的总和,如下所示,并在SUM> x + last_value的情况下迭代查询该表。

| ID | SOMENUMT | 
----------------
|  1 |       10 | 
|  2 |       12 | 
|  3 |        3 |
|  4 |        7 |
|  5 |        8 | 
|  6 |       10 | 

在不必运行迭代查询的地方还有更好的方法吗?

0 个答案:

没有答案