如何在 mysql 中搜索年月
how to search month with year in mysql
我有一个table。它有一个 varchar 类型的日期列。
我想使用日期搜索 table,但我只想搜索月份和年份。
示例: 12-2016
我该如何编写查询?
我希望那部分分配给 jasper
的变量
**示例:**WHERE ...............=$P{invDate}
我的 jasper 报告中的示例:
SELECT invoiceheader.inNo AS invoiceheader_inNo, invoiceheader.cusID AS invoiceheader_cusID, invoiceheader.soNo AS invoiceheader_soNo, invoiceheader.total AS invoiceheader_total, invoiceheader.dis AS invoiceheader_dis, invoiceheader.netTotal AS invoiceheader_netTotal, invoiceheader.cash AS invoiceheader_cash, invoiceheader.bal AS invoiceheader_bal, invoiceheader.date AS invoiceheader_date FROM invoiceheader invoiceheader WHERE ..................... ...............=$P{invDate}
我需要一个完美的查询以上space
尝试以下 -
select * from Table_name where month(date_column_name)=12 and year(date_column_name)=2016
试试这个(你已经为日期使用了 varchar 数据类型,所以 like 关键字将非常适合这种情况):
select * from table where date like concat('%' ,$P{invDate});
试试这个案例:
STR_TO_DATE(date_field, '%d-%m-%Y') < STR_TO_DATE('12-2016', '%m-%Y')
我有一个table。它有一个 varchar 类型的日期列。
我想使用日期搜索 table,但我只想搜索月份和年份。
示例: 12-2016
我该如何编写查询?
我希望那部分分配给 jasper
**示例:**WHERE ...............=$P{invDate}
我的 jasper 报告中的示例:
SELECT invoiceheader.inNo AS invoiceheader_inNo, invoiceheader.cusID AS invoiceheader_cusID, invoiceheader.soNo AS invoiceheader_soNo, invoiceheader.total AS invoiceheader_total, invoiceheader.dis AS invoiceheader_dis, invoiceheader.netTotal AS invoiceheader_netTotal, invoiceheader.cash AS invoiceheader_cash, invoiceheader.bal AS invoiceheader_bal, invoiceheader.date AS invoiceheader_date FROM invoiceheader invoiceheader WHERE ..................... ...............=$P{invDate}
我需要一个完美的查询以上space
尝试以下 -
select * from Table_name where month(date_column_name)=12 and year(date_column_name)=2016
试试这个(你已经为日期使用了 varchar 数据类型,所以 like 关键字将非常适合这种情况):
select * from table where date like concat('%' ,$P{invDate});
试试这个案例:
STR_TO_DATE(date_field, '%d-%m-%Y') < STR_TO_DATE('12-2016', '%m-%Y')