Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 编写查询以显示在6月份加入的唯一学生ID。按升序对结果排序_Sql_Date_Where Clause_Rdbms - Fatal编程技术网

Sql 编写查询以显示在6月份加入的唯一学生ID。按升序对结果排序

Sql 编写查询以显示在6月份加入的唯一学生ID。按升序对结果排序,sql,date,where-clause,rdbms,Sql,Date,Where Clause,Rdbms,这就是我试过的- select distinct studid from registration where to_char(doj,'MM')='june' order by studid; 但是我没有得到想要的结果。带有MM参数的TO_CHAR()将为您提供06,而不是6月份。您可以尝试下面的查询- select distinct studid from registration where to_char(doj,'MM')='06' order by studid; 与使用

这就是我试过的-

select distinct studid 
from registration 
where to_char(doj,'MM')='june'
order by studid;
但是我没有得到想要的结果。

带有MM参数的TO_CHAR()将为您提供06,而不是6月份。您可以尝试下面的查询-

select distinct studid 
from registration 
where to_char(doj,'MM')='06'
order by studid;
与使用TO_CHAR不同,您应该使用oracle特定的函数EXTRACT-

select distinct studid 
from registration 
where extract(month from doj) = 6
order by studid;

我假设您正在运行Oracle,正如使用
to_char()
所示

如果你想让学生在某一年的6月(比如2019年)加入,那么我建议检查
doj
是否有半开放时间间隔(这比在列上应用日期函数更有效):


看,你在使用MySQL还是Oracle
to_char()
不是MySQL函数。不要包含未读的标签。请在代码问题中给出一个--cut&paste&runnable代码,包括作为代码输入的最小代表性示例;期望和实际输出(包括逐字记录错误消息);标签和版本;清晰的说明和解释。给出你能给出的最少代码,即你显示的代码是OK的,扩展为你显示的代码是不OK的。(调试基础。)用于包含DBMS和DDL(包括约束和索引)的SQL,并将其作为格式化为表的代码输入。停止尝试编码你的总体目标&解释你期望从给定的代码中得到什么&为什么。
select distinct studid
from registration
where doj >= date '2019-06-01' and doj < date '2019-07-01'
order by studid
select distinct studid
from registration
where extract(month from doj) = 6
order by studid