平均相似字符串值

时间:2018-11-07 08:50:10

标签: sql mysqli

我创建了一个SQL查询,该查询将几个表合并为以下结构:

-------------------------------------------------------------------
ID      NAME     Test         Score   Date Completed   Display Name
2      User 1   Test Foobar 1  80       1528884606      Jakub Salt
2      User 1   Test Foobar 2  64       1528884606      Jakub Salt
2      User 1   Test Momo 1    70       1528884606      Jakub Salt
2      User 1   Test Momo 2    45       1528884606      Jakub Salt
2      User 1   Test Dodo      100      1528884606      Jakub Salt
3      User 2   Test Momo 1    77       1528884606      Brax Ramsey
3      User 2   Test Roro      98       1528884606      Brax Ramsey
3      User 2   Test Momo 2    25       1528884606      Brax Ramsey
3      User 2   Test Foobar 2  100      1528884606      Brax Ramsey
3      User 2   Test Foobar 1  84       1528884606      Brax Ramsey
-------------------------------------------------------------------

这是我用来获取此数据的查询:

SELECT
  ift_users.ID,
  ift_users.user_login,
  ift_posts.post_title,
  ift_learndash_user_activity_meta.activity_meta_value,
  ift_learndash_user_activity.activity_completed,
  ift_users.display_name
FROM ift_learndash_user_activity
  INNER JOIN ift_users
    ON ift_learndash_user_activity.user_id = ift_users.ID
  INNER JOIN ift_learndash_user_activity_meta
    ON ift_learndash_user_activity.activity_id = ift_learndash_user_activity_meta.activity_id
  INNER JOIN ift_posts
    ON ift_learndash_user_activity.post_id = ift_posts.ID
  INNER JOIN ift_usermeta
    ON ift_users.ID = ift_usermeta.user_id
WHERE ift_learndash_user_activity.activity_type = 'quiz'
AND ift_learndash_user_activity_meta.activity_meta_key = 'percentage'
AND ift_usermeta.meta_key = 'learndash_group_users_9012'
AND ift_usermeta.meta_value = 9012

我想要实现的是一张表,该表将提供同一主题下的两项测试的平均值,例如:

-------------------------------------------------------------------
ID      NAME     Test         Score   Date Completed   Display Name
2      User 1   Test Foobar    72       1528884606      Jakub Salt
2      User 1   Test Momo      57.5     1528884606      Jakub Salt
2      User 1   Test Dodo      100      1528884606      Jakub Salt
3      User 2   Test Momo      51       1528884606      Brax Ramsey
3      User 2   Test Roro      98       1528884606      Brax Ramsey
3      User 2   Test Foobar    92       1528884606      Brax Ramsey
-------------------------------------------------------------------

我不太确定如何获得这种结果,因此不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用av​​g()聚合和分组依据

var test = dateFns;


function comparedate(){
    var borndate = dateFns.parse(document.getElementById("borndate").value);
    var date = dateFns.parse(new Date());
    
    console.dir(date)
    console.dir(borndate)
    
    if (dateFns.isAfter(borndate, date)) {
        alert("Looks like you are to young!");
    } else {
        return true;
    }
}