MySQL选择1行中不同行的总和

时间:2017-08-28 09:44:52

标签: mysql select

我有一张有多个人名的桌子。每个人在几个职位上多次出现几次。我想选择不同的人,每个工作的工作时间总和。 示例:

PersonName     Job1     Job2     Job3

  Eliot        14:55    23:17     80:12  

1 个答案:

答案 0 :(得分:0)

您应将工作时间存储为分钟(例如整数)或小时(例如小数),以便能够计算总和。在这种情况下,您可以使用以下代码:

public static String getRequest() {
    StringBuffer stringBuffer = new StringBuffer("");
    BufferedReader bufferedReader = null;
try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet();

        URI uri = new URI("http://10.1.1.83/outlet?2=OFF");
        httpGet.setURI(uri);
        httpGet.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials("admin", "1234"),
                HTTP.UTF_8, false));

        HttpResponse httpResponse = httpClient.execute(httpGet);
        InputStream inputStream = httpResponse.getEntity().getContent();
        bufferedReader = new BufferedReader(new InputStreamReader(
                inputStream));

        String readLine = bufferedReader.readLine();
while (readLine != null) {
            stringBuffer.append(readLine);
            stringBuffer.append("\n");
            readLine = bufferedReader.readLine();
        }
    } catch (Exception e) {
// TODO: handle exception
    } finally {
if (bufferedReader != null) {
try {
                bufferedReader.close();
            } catch (IOException e) {
// TODO: handle exception
            }
        }
    }
return stringBuffer.toString();
}

现在您的工作时间似乎存储为字符串。您可以编写一个考虑到这一点的查询,但将工作时间存储为数字要容易得多。