Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何在sql中搜索介于两个范围之间的精确值?_Mysql_Sql_Netbeans 7 - Fatal编程技术网

Mysql 如何在sql中搜索介于两个范围之间的精确值?

Mysql 如何在sql中搜索介于两个范围之间的精确值?,mysql,sql,netbeans-7,Mysql,Sql,Netbeans 7,我的表中有这些字段 发票号 日期 项目代码 项目名称 数量 总数 我想在netbeans中的一个表中筛选和获取两个时间段之间的值,如下所示 示例:2014年1月1日至2014年3月1日期间项目调用项目1的总销售额 我使用的查询是 String sql="select sales_invoice_no,date,item_name,quantity,free,total FROM sales_invoice2items where date between '"+repdate.

我的表中有这些字段

发票号

日期

项目代码

项目名称

数量

总数

我想在netbeans中的一个表中筛选和获取两个时间段之间的值,如下所示

示例:2014年1月1日至2014年3月1日期间项目调用项目1的总销售额

我使用的查询是

        String sql="select sales_invoice_no,date,item_name,quantity,free,total FROM  sales_invoice2items where date between '"+repdate.getText()+"' and '"+repdate2.getText()+"'";
        Statement st1 = database.getconnection().prepareStatement(sql);
        ResultSet rs = st1.executeQuery(sql);

        reptable1.setModel(DbUtils.resultSetToTableModel(rs));

我的代码工作正常,它会过滤时间段之间的值,但不会过滤我需要的项目。请帮助。

看起来您没有添加过滤器:

这是您的代码:

String sql="select sales_invoice_no,date,item_name,quantity,free,total FROM  sales_invoice2items where date between '"+repdate.getText()+"' and '"+repdate2.getText()+"'";
如果是:

String sql="select sales_invoice_no,date,item_name,quantity,free,total FROM  sales_invoice2items where Item_name = item1 and date between '"+repdate.getText()+"' and '"+repdate2.getText()+"'";
请按以下步骤进行尝试:

select 
sales_invoice_no,date,item_name,quantity,free,total 
FROM  sales_invoice2items 
where item_code='item1' and date between 'repdate1' and 'repdate2';

它不会过滤,因为你没有告诉它。将项目名称添加到
WHERE
子句中:

String sql="select sales_invoice_no,date,item_name,quantity,free,total "+
        "FROM  sales_invoice2items where date between '"+
        repdate.getText()+"' and '"+repdate2.getText()+"' and item_name='<<name>>'";
String sql=“选择销售\发票\编号、日期、项目\名称、数量、免费、总计”+
“来自销售发票2项,其中日期介于”+
repdate.getText()+“'和”“+repdate2.getText()+”'和项名称=”;

另外,请正确使用准备好的语句,不要将中的值串联在一起,而是将它们与查询分开发送。

Thanx它可以工作!感谢你的帮助,我的兄弟。Thanx againThanx它能工作!感谢你的帮助,我的兄弟。Thanx againThanx它能工作!感谢你的帮助,我的兄弟。Thanx Again不客气,别忘了接受答案:)啊,调情-你真的应该使用,否则后果自负。