MySQL在命令之间选择 [英] MySQL Select Between Command

查看:129
本文介绍了MySQL在命令之间选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个名为effdate的字段,其中包含正确的日期和字段工作状态。



 选择 * 来自 personinfo 其中 effdate   '  12/01/2013'  '  12/21/2013'  workstatus '  HIRED''  REASGD'订单 姓氏< span class =code-keyword> ASC ; 





每当我编码时,MYSQL也会显示来自1的数据-21但是年份显示1993,1992,1892这样的东西?



有没有可能的代码?如果我输入 '12 / 01/2013' '12 / 21/2013'我只想输入数据显示2013年12月1日至21日。



TY帮助。

解决方案

解决方案1:

尝试使用括号对两个条件进行分组:

  SELECT  * 
FROM personinfo
WHERE (effdate 之间的code-keyword> ' 12/01/2013' ' 12/21/2013'(workstatus in ' HIRED'' REASGD'))
< span class =code-keyword> ORDER
BY 姓氏 ASC ;



< b>解决方案2:

使用子查询:

  SELECT  * 
FROM
SELECT *
FROM personinfo
WHERE (effdate ' 12/01/2013' ' 12/21/2013'
AS T
WHERE (workstatus in ' HIRED'' REASGD '))
ORDER BY 姓氏 ASC ;


好吧,我的朋友,



尝试这样做



SELECT * FROM personinfo WHERE(effdate BETWEEN'2013-12-01'and'2013-12-21')AND(workstatus in('HIRED','REASGD'))ORDER BY姓氏ASC



在上面的代码中,我假设:



1. effdate有一个数据DATE的类型。



2.我使用日期格式输入yyyy-mm-dd(这是phpmyadmin在列中输入日期使用的内容





希望它能帮到你解决问题。如果有帮助或标记为已解决,请评价这个答案:)



有问候

Tushar Srivastava


I have a field in my database named effdate which consist proper date and a also a field workstatus.

select * from personinfo where effdate between '12/01/2013' and '12/21/2013' and workstatus in ('HIRED','REASGD') Order by surname ASC;



everytime i code this,MYSQL also shows the data from 1-21 but the year show 1993,1992,1892 something like that?

Is there any possible code for this? if i type '12/01/2013' and '12/21/2013' i only want the data to show between 1 and 21 of december 2013.

TY for the help.

解决方案

Solution 1:
Try to group both conditions using brackets:

SELECT *
FROM personinfo
WHERE (effdate between '12/01/2013' and '12/21/2013') and (workstatus in ('HIRED','REASGD'))
ORDER BY surname ASC;


Solution 2:
Use subquery:

SELECT *
FROM (
    SELECT *
    FROM personinfo
    WHERE (effdate between '12/01/2013' and '12/21/2013')
    ) AS T
WHERE (workstatus in ('HIRED','REASGD'))
ORDER BY surname ASC;


Alright my friend,

Try to do this

SELECT * FROM personinfo WHERE (effdate BETWEEN '2013-12-01' AND '2013-12-21') AND (workstatus in ('HIRED', 'REASGD')) ORDER BY surname ASC

In the above code, I assumed that :

1. effdate has a data type of DATE.

2. I used format for date to input yyyy-mm-dd (Which is what phpmyadmin uses for input date in a column


Hope that it will help solve your problem. Do rate this answer if it helped or mark as solved :)

With Regards
Tushar Srivastava


这篇关于MySQL在命令之间选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆