两个不同的列和sql之间的查询

时间:2017-10-04 06:42:24

标签: mysql sql

我的表

id  Type        date              
2  Expense      2017-09-07
3  Expense       2017-09-07
5  Expense       2017-09-06
6  Income        2017-09-06
2  Income        2017-09-07
3  Income        2017-09-07
5  Income        2017-09-05
6   Expense      2017-09-04

我在一个选择查询中需要此结果  费用和日期之间(2017-09-06和2017-09-07)

id  Type        date              
2  Expense       2017-09-07
3  Expense       2017-09-07
5  Expense       2017-09-06

4 个答案:

答案 0 :(得分:-1)

SELECT * FROM `table` 
WHERE `Type`='Expense'
AND `date` BETWEEN '2017-09-06 00:00:00' AND '2017-09-07 00:00:00'
ORDER BY date ASC;

答案 1 :(得分:-1)

在查询结尾处只是一个简单的WHERE子句,请查看HERE以便更好地理解。它是SQL

中最基本但最重要的部分之一

添加

WHERE Type = 'Expense' 
AND date BETWEEN '2017-09-06' AND '2017-09-07'

FROM

SELECT部分之后

答案 2 :(得分:-1)

很简单:

select * from yourtable t where t.type='Expense' and t.date BETWEEN '2009-06-25' AND '2009-07-01';

答案 3 :(得分:-1)

你可以使用它。

SELECT * FROM MyTable WHERE (Type = 'Expense') AND (date BETWEEN('2017-09-06' AND '2017-09-07')) ORDER BY date DESC