Mysql query problem

后端 未结 8 944
逝去的感伤
逝去的感伤 2020-12-22 03:24

I have a problem with my mysql query.

My database:

sections
id
section_name

grades
id
user_id
section_id
date
grade

I want my data

8条回答
  •  再見小時候
    2020-12-22 03:59

    I recently had to do something similiar, but with T-SQL so you'll have to change it yourself to get it to work in MySQL (which I don't have installed here so I can't check for you I'm afraid).

    Add to the WHERE clause:

    AND grades.date = (SELECT TOP 1 date 
                         FROM grades 
                           WHERE date > GETDATE() 
                       ORDER BY ABS(CONVERT(FLOAT,GETDATE() - date)))
    

    GETDATE() is equivalent to NOW(), TOP 1 is like LIMIT 1 and the other functions, well I don't know the MySQL equivalents off the top of my head!

提交回复
热议问题