存储过程将查询运行日期和总数保存在HANA数据库中-每天早上6:30运行

时间:2018-07-24 15:45:29

标签: sql database stored-procedures hana

在存储过程中寻求帮助,以便每天早上将查询结果保存在HANA数据库的“ HANADB_Table”中。存储过程应每天运行查询,并每天早晨在新行中附加运行日期和计数。 我有一个查询,该查询当前为我提供了结果:

<ListBox>
 <ListBox.ItemTemplate>
   <DataTemplate>
     <StackPanel Orientation="Horizontal" Background="Transparent">
       <TextBlock Text="{Binding}"/> 
     </StackPanel>     
     <StackPanel.ContextMenu>
       <ContextMenu>
        <MenuItem Header="Edit" />
        <MenuItem Header="Delete" />   
       </ContextMenu>
    </StackPanel.ContextMenu>         
  </DataTemplate>
 </ListBox.ItemTemplate>
  <ListBox.Items>
   <sys:String>Item 1</sys:String>
   <sys:String>Item 2</sys:String>
  </ListBox.Items>
</Listbox>

HANA数据库中的表是这样的:

Run Date    Count 1 Count 2     Count 3
1-Jun   1125    63  1188

给出结果的查询是:

CREATE COLUMN TABLE HANADB_Table (
    Run_Date DATE not null,
    Count1 INTEGER not null,
    Count2 INTEGER not null,
    Count3 INTEGER not null
);

感谢所有帮助!预先谢谢你。

1 个答案:

答案 0 :(得分:0)

好吧,简单的答案是将类似以下的语句放入存储过程中。然后可以通过 SAP HANA XS调度程序YouTube video on HANA job scheduling)或外部工具(例如, <?php include "config.php"; $from_date = $_GET["from_date"]; $to_date = $_GET["to_date"]; $City = $_GET["City"]; $cityExplode = explode(",",$City); $cityImplode = "'".implode("','", $cityExplode)."'"; $query = "SELECT * from $dbTablePrefixMaster WHERE Date BETWEEN '".$from_date."' AND '".$to_date."' AND City IN ($cityImplode) ORDER BY Date ASC"; $result = $db->query($query) or die(mysqli_error($db)); if($result->num_rows >0) { $delimiter = ","; $emailArr = array(); while($row=$result->fetch_assoc()) { if(!in_array($row['Email'],$emailArr)) { $fileContent.= "".stripslashes($row['Rep']).",".stripslashes($row['Name']).",".stripslashes($row['Last_Name']).",".stripslashes($row['Email']).",".stripslashes($row ['Add1']).",".stripslashes($row['Add2']).",".stripslashes($row['City']).",".stripslashes($row['State']).",".stripslashes($row['Zip']).",".stripslashes($row['PH_Home']).",".stripslashes ($row['PH_Work']).",".stripslashes($row['PH_Mobile']).",".stripslashes($row['Date']).",".stripslashes($row['Business_Name'])."\n"; $emailArr[] = $row['Email']; } } $file = "../folder/folder/folder/Upload.csv"; // File to Save chmod($file, 0777); file_put_contents($file, $fileContent); echo 'echo stuff here'; } else { echo 'no record found'; exit; } ?>

语句看起来像这样

cron

如果您想采用这种方法,则可以考虑对SUM列使用INSERT into "HANADB_Table" ( Run_Date, Count1, Count2, Count3) (select current_date, sum(Count1), sum(Count2), sum(Count3) from "TableName"); ,因为随着时间的推移,聚合值通常会变得非常大。

此外,这种定时快照聚合的方法通常被认为不太灵活。在许多情况下,人们宁愿努力直接从源表中获取任意时间点的结果聚合。