【问题标题】:Sql query to Select data for same dateSql查询选择同一日期的数据
【发布时间】:2023-03-29 21:55:01
【问题描述】:

我有一个包含 assignment_id、student_id、assignment_name 和 assignment_date 的表。我必须编写一个 SQL 查询来获取在同一日期提交 2 个作业的学生列表。我还需要输出中的 assignment_name 和 assignment_date。我不知道我可以写哪个查询来获取这些数据。任何帮助将不胜感激

【问题讨论】:

  • (1) 您应该显示您尝试的查询。 (2) 你应该标记你正在使用的数据库。
  • 嗨,戈登,我正在使用 Oracle SQL。我对 SQL 查询很陌生,完全不知道从哪里开始
  • 嗨,戈登,我正在使用 Oracle SQL。我对 SQL 查询很陌生,完全不知道从哪里开始
  • 提示:Group by student_id,training_date + Having

标签: sql oracle date


【解决方案1】:

你可以试试这样的

在 MYSQL 查询中

  SELECT student_id, training_date, GROUP_CONCAT(assignment_name)
     FROM
   table_name
   GROUP BY student_id, training_date HAVING COUNT(*) = 2

"Is there any function in oracle similar to group_concat in mysql?" 可能会帮助您替换 oracle SQL

中的 GROUP_CONCAT

【讨论】:

【解决方案2】:

你可以使用exists

select t.*
from table t
where exists (select 1 
              from table t1 
              where t1.student_id = t.student_id and 
                    t1.training_date = t.training_date and 
                    t1.assignment_id <> t.assignment_id
             );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 2019-04-10
    相关资源
    最近更新 更多