英文:
can you use LIKE and AND together
问题
我正在尝试获取在2016年和2018年下单的所有订单:
SELECT OrderID, OrderDate
FROM Orders
WHERE OrderDate LIKE '2016%' OR OrderDate LIKE '2018%';
但它只显示2016年的结果。
我尝试了以下查询:
SELECT OrderID, OrderDate
FROM Orders
WHERE YEAR(OrderDate) = 2016;
但它返回一个空白屏幕,我理解这是因为没有一行的值等于'2016-%m-%d'。
我还尝试了使用'IN',结果与'='相同。在这一点上,我尝试了不同的运算符,但结果都一样,要么出现错误,要么是一个空白屏幕。
有人知道我做错了什么吗?
英文:
I'm trying to get all the orders that have been placed on 2016 and on 2018
SELECT OrderID, OrderDate
FROM Orders
WHERE OrderDate LIKE '2016%' AND '2018%';
But it only show the results of 2016
I tried
SELECT OrderID, OrderDate
FROM Orders
WHERE OrderDate = date('2016-%m-%d');
But it returns a empty screen, I understand that's because there isn't a row with a value of '2016-%m-%d'
I also tried with 'IN' and its the same result as '=' At this point I have tried with different operator but the results are the same. either error or a white screen.
Does anyone know what am I doing wrong?
答案1
得分: 2
你必须在AND
的两边重复整个表达式:
WHERE OrderDate LIKE '2016%' AND OrderDate LIKE '2018%';
但这对于任何值来说都不可能成立。没有东西可以同时以2016
和2018
开头。也许你想要用OR
代替AND
?
英文:
You have to repeat the whole expression on both sides of AND
:
WHERE OrderDate LIKE '2016%' AND OrderDate LIKE '2018%';
But that can't be true for any value. Nothing can start both with 2016
and 2018
at the same time. Maybe you wanted OR
instead of AND
?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论