简体   繁体   English

PhpMyAdmin SQL 查询表,其中同名行的日期在某个日期之前和某个日期之后

[英]PhpMyAdmin SQL query table where the rows with same name has date before certain date AND after certain date

I've just installed WAMP server in my Windows 10 computer and I'm playing around with it to learn how to query SQL table.我刚刚在我的 Windows 10 计算机中安装了 WAMP 服务器,我正在使用它来学习如何查询 SQL 表。 So I make a case which I don't know how to query it.所以我做了一个我不知道如何查询的案例。 I've searched if my question is a duplicate question in this site, but since my limited English - I can't find questions in this site which the same like mine.我已经搜索过我的问题是否是本网站中的重复问题,但由于我的英语有限 - 我无法在本网站中找到与我相同的问题。

My table name is test.我的表名是测试。 And it look something like this in PhpMyAdmin:在 PhpMyAdmin 中看起来像这样:
在此处输入图像描述

The query in ordinary language is something like this:普通语言的查询是这样的:
show the rows which name has TGL before 2020/01/01 and has TGL after 2022/02/01显示名称在 2020/01/01 之前具有 TGL 并且在 2022/02/01 之后具有 TGL 的行

So the expected result is the one which I mark red color:所以预期的结果是我标记为红色的结果:
在此处输入图像描述

From questions in this site which is similar to my question is to query the table using NOT BETWEEN and using < or > .从本网站中与我的问题类似的问题中,使用NOT BETWEEN和使用< or >来查询表。 So I try that question's answer like this in PhpMyAdmin:所以我在 PhpMyAdmin 中尝试这个问题的答案:

SELECT * FROM `test` WHERE TGL < "2020/01/01" OR TGL > "2022/02/01"

another try using NOT BETWEEN另一个尝试使用 NOT BETWEEN

SELECT * FROM `test` WHERE TGL NOT BETWEEN "2020/01/01" AND "2022/02/01"

But the query result (logically) is including another row (CCC) which has TGL before 2020/01/01 or has TGL after 2022/02/01 (BBB).但是查询结果(逻辑上)包括另一行(CCC),该行在 2020/01/01 之前具有 TGL 或在 2022/02/01 之后具有 TGL(BBB)。 Like the image below:如下图所示:

在此处输入图像描述

Playing illogical, so I also try to make the query like this:玩不合逻辑,所以我也尝试这样查询:

SELECT * FROM `test` WHERE TGL < "2020/01/01" AND TGL > "2022/02/01"

And the query result show an empty row.并且查询结果显示一个空行。

As per the answer to my question, so I try:根据我的问题的答案,所以我尝试:

SELECT * FROM `test` WHERE TGL NOT BETWEEN "2020/01/01" AND "2022/02/01" GROUP BY NAMA

But the query result is like this:但是查询结果是这样的:
在此处输入图像描述

Since I still can't find the question in this site like mine, I'd be glad if someone can give me a link for duplicate question - so I can delete this question.由于我仍然无法在这个网站上找到像我这样的问题,如果有人可以给我一个重复问题的链接,我会很高兴 - 这样我就可以删除这个问题。

But if there is no duplicate question like mine, how do I query the date to get the expected result?但是如果没有像我这样的重复问题,我如何查询日期以获得预期的结果?

Any kind of respond would be much appreciated.任何形式的回应将不胜感激。
Thank you in advanced.提前谢谢你。

You just have to add 'group by' to get your acquired result:您只需添加“分组依据”即可获得您获得的结果:

SELECT * FROM `test` WHERE TGL NOT BETWEEN "2020/01/01" AND "2022/02/01" GROUP BY NAMA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM