使用MySQL

时间:2016-09-25 18:12:11

标签: mysql

我有数据库来存储温度。每小时有三到五个温度,我想获得一小时的第一个和最后一个温度,但我无法创建合适的子查询。

以下是按小时获取温度的主要查询。

SELECT HOUR(time) AS h, max(temp_in) as max, min(temp_in) as min, count(temp_in) as count 
FROM tbl_temps 
GROUP BY h; 

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以使用联合和子查询

function generatePdf(){
    //Create a temporary spreadsheet, to store the desired sheet from the spreadsheet in. 
    var originalSpreadsheet = SpreadsheetApp.getActive();
    originalSpreadsheet.setActiveSheet(originalSpreadsheet.getSheets()[4]);
    var name = "Testname"
    var newSpreadsheet = SpreadsheetApp.create(name);
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    sheet = originalSpreadsheet.getActiveSheet();
    sheet.copyTo(newSpreadsheet);
    //Save the desired sheet as pdf
    var pdf = DriveApp.getFileById(newSpreadsheet.getId()).getAs('application/pdf');
    var saveCopy = DriveApp.createFile(pdf);
    //Delete temporary spreadsheet
    DriveApp.getFilesByName(name).next().setTrashed(true);
    //Move the pdf file from the rootfolder to the folder where invoices are to be stored.
    var files = DriveApp.getRootFolder().getFiles();
    while (files.hasNext()) {
        var file = files.next();
        var destination = DriveApp.getFolderById("0B3ok04PZOVbgLXA2dy14MVlLRXM");
        destination.addFile(file);
        var pull = DriveApp.getRootFolder();
        pull.removeFile(file);    
    }
}