#Query根据特定条件填充不同的结果。 (挑战者查询)

时间:2018-09-15 10:56:22

标签: mysql

请任何人协助我们解决最终的挑战者查询。

表名:attendance_tbl

nota_id represents present or absent nota_id ='1' => PRESENT

priod_id

1=>Hour-1 

2=>Hour-2

3=>Hour-3

4=>Hour-4

5=>Hour-5

如果priod_id包含值1或2或3或4,则根据条件我们将百分比设置为0.25

如果priod_id包含1或2或3或4或5,则根据条件我们将百分比设置为0.2。

如果priod_id大于4,如果在任何一天其值为5,那么我们将所有1,2,3,4的百分比都设置为0.2

如果priod_id为4,则必须将所有1,2,3,4的百分比设置为0.25

示例:

Date : 2018-08-31
priod_id =1 , priod_id =2 priod_id =5
Then set Percentage = 0.2 for 1,2,5

priod_id =1 , priod_id =2 priod_id =4
Then set Percentage = 0.25 for 1,2,4 

Please refer to the query we have tried the least.


SELECT *, 
      IF(`nota_id` = '1', Percentage,'0.0') AS ABSENT 
from (SELECT *, CASE WHEN (max(`priod_id`) > 4) THEN "0.2" 
                     ELSE "0.25" 
                END as Percentage 
      FROM `attendance_tbl` 
      WHERE DATE(attend_date) BETWEEN '2018-08-01' AND '2018-08-31' 
        AND sid = '74' 
      GROUP BY sid, attend_date) t

Table Results & Structure

1 个答案:

答案 0 :(得分:0)

我们找到了答案。

SELECT *,
           案件              WHEN(max({router.get("/googleToken", function (req, res) { // Function to retrieve forms after AUTH function listFiles(auth) { const drive = google.drive({version: 'v3', auth}); drive.files.list({ q: "mimeType='application/vnd.google-apps.form'", fields: 'nextPageToken, files(id, name)', }, (err, res) => { if (err) return console.log('The API returned an error: ' + err); var files = res.data.files; // Callback function to return files function callback() { return files; }; if (files.length) { // CALL callback to return data callback(); } else { console.log('No files found.'); } }); } var code = req.query.code; oauth2Client.getToken(code, function (err, tokens) { if (err) { console.log(err); res.send(err); return; } else { oauth2Client.setCredentials(tokens); var forms = listFiles(oauth2Client); res.send(forms); } }); }); )> 4)然后                “ 0.2”              其他                “ 0.25”            以百分比结尾,
           COUNT(priod_id)为HOURS,            COUNT(箱)                    当nota_id ='1'时                      1个                  END)AS PR       来自priod_id A      DATE('2018-08-01')和DATE('2018-08-31')之间的DATE(attend_date)        AND sid ='60'   GROUP BY DATE(attend_date)