dsbowmvth16379079 2013-04-19 15:42
浏览 160
已采纳

我可以在select语句中使用两个Where

I'm trying to get a date range and a transaction type in a query. I'm working in PHP with a Mysql database. Originally, the statement was

         ("select * from accounting WHERE date between '$startdate' AND 
        '$enddate'",$prop);

It works beautifully, no issues @ all. But I also need it to select a column in the database called transaction type. Here's how I modified it:

           ("SELECT date, account, description, Income FROM accounting where 
           transactiontype = 'Income' and WHERE date between '$startdate' AND 
           '$enddate' order by date ASC",$prop);

I'm getting the error message: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE date between '2012/09/01' AND '2013/04/17' order by date ASC' at line 1 Query: SELECT date, account, description, Income FROM accounting where transactiontype = 'Income' and WHERE date between '2012/09/01' AND '2013/04/17' order by date ASC Any Help would be greatly appreciated.

  • 写回答

3条回答 默认 最新

  • duanpanzhu2910 2013-04-19 15:43
    关注

    AND is enough, you don't need the seconde WHERE.

    ("SELECT `date`, account, description, Income 
      FROM accounting 
      WHERE transactiontype = 'Income' 
      AND `date` between '$startdate' 
      AND '$enddate' order by `date` ASC",$prop);
    

    By the way, try to avoid reserved keywords as table / columns name (like date). You'll have to escape them all the time (and will forget that all the time also).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教