简单查询以按ID,日期,时间查找员工ID,日期和minimum_time以及maximum_time顺序

时间:2017-01-20 10:21:01

标签: php sql mysqli xampp

9

如何从此表中按ID,日期,时间查找员工ID,日期和minimum_time以及maximum_time订单?

4 个答案:

答案 0 :(得分:1)

SELECT emp_id,
       date,
       MIN(time) AS in_time,
       MAX(time) AS out_time
FROM yourTable
GROUP BY emp_id,
         date
ORDER BY emp_id, date

MIN()MAX()函数会在每个日期找到每位员工的最早和最晚时间。

答案 1 :(得分:0)

您的查询语法很简单

SELECT atr1, atr2,.. FROM table_name ORDER BY atr1, atr2,..

答案 2 :(得分:0)

您可以使用SELECT Query

SELECT employee.id, employee.date, employee.minimum_time, employee.maximum_time From table_name ORDER BY employee.id

答案 3 :(得分:0)

尝试:

private void downloadFTPFileToLocal(FolderPath   _folderName,
                                        FileName    _fileName,
                                        FileName    fileNameLocal)
{
    System.Exception                clrException;
    Object                          ftpObject;
    System.Net.FtpWebRequest        ftpWebRequest;
    System.Net.NetworkCredential    networkCredential;
    System.Net.WebProxy             webProxy;
    System.IO.Stream                stream;
    System.IO.StreamReader          streamReader;
    System.IO.StreamWriter          streamWriter;
    System.Text.Encoding            encoding;
    boolean                         errorFTP;
    Filename                        fileNameLocal;
    object                          ftpWebResponse;
    System.Net.FtpWebResponse       response;


    void closeAll()
    {
        if (streamReader)
        {
            streamReader.Close();
        }
        if (streamWriter)
        {
            streamWriter.Close();
        }
        if (stream)
        {
            stream.Close();
        }
        if (ftpWebResponse)
        {
            ftpWebResponse.Close();
        }
    }
;

    try
    {
        try
        {
            ftpObject     = System.Net.WebRequest::Create(_folderName, _fileName);
            ftpWebRequest = ftpObject;

            networkCredential = new System.Net.NetworkCredential(FTPLogin, FTPPassword);
            ftpWebRequest.set_Credentials(networkCredential);

            ftpWebRequest.set_Method(#RETR);
            ftpWebRequest.set_Timeout(#TimeOut);

            if (Param.FTPMode == FTPMode::Active)
            {
                ftpWebRequest.set_UsePassive(false);
            }
            else
            {
                ftpWebRequest.set_UsePassive(true);
            }

            if (useProxy)
            {
                webProxy  = System.Net.WebProxy::GetDefaultProxy();
                webProxy.set_UseDefaultCredentials(true);
                ftpWebRequest.set_Proxy(webProxy);
            }
            else
            {
                ftpWebRequest.set_Proxy(new System.Net.WebProxy());
            }

            ftpWebResponse = ftpWebRequest.GetResponse();
        }
        catch (Exception::CLRError)
        {
            if (useProxy)
            {
                useProxy = false;
                retry;
            }
            else
            {
                throw Exception::CLRError;
            }
        }

        response = ftpWebResponse;

        stream       = response.GetResponseStream();
        encoding     = System.Text.Encoding::get_Default(); // to check encoding
        streamReader = new System.IO.StreamReader(stream, encoding);

        if (System.IO.File::Exists(fileNameLocal))
        {
            System.IO.File::Delete(fileNameLocal);
        }

        streamWriter = new System.IO.StreamWriter(fileNameLocal, false, encoding);
        streamWriter.Write(streamReader.ReadToEnd());
        streamWriter.Close();

        response.Close();

        closeAll();
    }
    catch (Exception::CLRError)
    {
        clrException = CLRInterop::getLastException();

        if (clrException)
        {
            clrException = clrException.get_InnerException();
            if (clrException)
            {
                error(clrException.get_Message());
            }
        }

        if (useProxy)
        {
            useProxy = false;
            retry;
        }
        else
        {
            closeAll();
        }

        errorFTP = true;
    }
    catch
    {
        closeAll();
        errorFTP = true;
    }
}

正如我所看到的,许多日期都有相同的emp_id,因此按日期分组将获得每个日期的所有数据。