加入并排序后可以分组吗?

时间:2018-12-13 16:11:53

标签: sql oracle

我只是想按职位ID分组,加入后按职位排序。我可以在我的代码中找出答案吗?

  select job_id, job_status, avg_rec_time_millis from (select  
                job.job_id, 
                job.job_status,
                job_step.avg_rec_time_millis
                from job
                right outer join job_step on job.job_id= job_step.job_id)
    WHERE job_status = 'Extracted'
    Order by job_id;

2 个答案:

答案 0 :(得分:0)

您必须在func getWatsonToken(apiKey string) (string, error) { // Base on the Watson Swift and Python SDKs // https://github.com/watson-developer-cloud/restkit/blob/master/Sources/RestKit/Authentication.swift // https://github.com/watson-developer-cloud/python-sdk/blob/master/watson_developer_cloud/iam_token_manager.py const tokenUrl = "https://iam.bluemix.net/identity/token" form := url.Values{} form.Set("grant_type", "urn:ibm:params:oauth:grant-type:apikey") form.Set("apikey", apiKey) form.Set("response_type", "cloud_iam") // Token from simple "http.PostForm" does not work either //resp, err := http.PostForm(tokenUrl, form) req, err := http.NewRequest(http.MethodPost, tokenUrl, nil) if err != nil { log.Printf("could not create HTTP request to get Watson token: %+v", err) return "", nil } header := http.Header{} header.Set("Content-Type", "application/x-www-form-urlencoded") header.Set("Accept", "application/json") // "Yng6Yng=" is "bx:bx" header.Set("Authorization", "Basic Yng6Yng=") req.Header = header req.Body = ioutil.NopCloser(bytes.NewReader([]byte(form.Encode()))) resp, err := http.DefaultClient.Do(req) if err != nil { log.Printf("problem executing HTTP request to get Watson token: %+v", err) return "", err } defer resp.Body.Close() if resp.StatusCode != 200 { return "", errors.New(fmt.Sprintf("failed to get Watson token: %d", resp.StatusCode)) } jsonBody, err := ioutil.ReadAll(resp.Body) if err != nil { log.Printf("problem reading Watson token from response body: %+v", err) } tokenResponse := &struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` TokenType string `json:"token_type"` ExpiresIn int64 `json:"expires_in"` Expiration int64 `json:"expiration"` }{} err = json.Unmarshal(jsonBody, tokenResponse) if err != nil { log.Printf("could not parse Watson token response: %+v", err) return "", err } return tokenResponse.AccessToken, err } 之前分组,例如:

ORDER BY

此外,您需要“汇总” select job_id, sum(job_status), sum(avg_rec_time_millis) from (select job.job_id, job.job_status, job_step.avg_rec_time_millis from job right outer join job_step on job.job_id= job_step.job_id) WHERE job_status = 'Extracted' GROUP BY job_id Order by job_id; 子句中不存在的其他列。任何聚合函数都可以:最小值,最大值,总和,平均值等。

答案 1 :(得分:0)

没有一些示例,可能很难回答这个问题,但是根据我对您的情况的了解,我会尝试:

select j.job_id, j.job_status, sum(s.avg_rec_time_millis) as sum_rec_time_millis
  from job j
 inner join job_step s on j.job_id = s.job_id
 where j.job_status = 'Extracted'
 group by j.job_id, j.job_status
 order by j.job_id;