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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路