如何在mysql

时间:2017-01-03 13:58:09

标签: mysql jasper-reports

我有一张桌子。它有一个varchar类型的日期列 我想使用日期搜索该表,但我想只搜索一年中的月份。

示例: 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}

我需要对上述空间进行完美查询

3 个答案:

答案 0 :(得分:1)

试试这个(你已经使用varchar数据类型作为日期,所以像关键字一样非常适合这种情况):

 select * from table where date like concat('%' ,$P{invDate});

答案 1 :(得分:0)

试试这个案例:

STR_TO_DATE(date_field, '%d-%m-%Y') < STR_TO_DATE('12-2016', '%m-%Y')

答案 2 :(得分:-1)

尝试以下操作 -

select * from Table_name where month(date_column_name)=12 and year(date_column_name)=2016