Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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选择查询_Mysql_Sql_Select - Fatal编程技术网

带条件的Mysql选择查询

带条件的Mysql选择查询,mysql,sql,select,Mysql,Sql,Select,我有一个Mysql表,其中包含以下数据 |ID | Date | BillNumber|BillMonth | Amount | Name |AccNum | | 2 |2015-09-25| 454345 | 092015 | 135.00 |Andrew Good| 735976| | 3 |2015-09-26| 356282 | 092015 | 142.00 |Peter Pan | 123489| | 4 |2015-08-11| 312738

我有一个Mysql表,其中包含以下数据

|ID | Date     | BillNumber|BillMonth | Amount | Name      |AccNum |
| 2 |2015-09-25| 454345    | 092015   | 135.00 |Andrew Good| 735976|
| 3 |2015-09-26| 356282    | 092015   | 142.00 |Peter Pan  | 123489|
| 4 |2015-08-11| 312738    | 082015   | 162.00 |Andrew Good| 735976|
| 5 |2015-07-12| 287628    | 072015   | 220.67 |Andrew Good| 735976|
| 6 |2015-06-12| 100756    | 062015   | 556.34 |Andrew Good| 735976|

我想要实现的是使用AccNum 735976检索Andrew Good 2015年9月份的BillMonth数据,前提是用户可以输入任何BillNumberpast/current

如果对该行感兴趣的原因是因为它是他最新的行,请尝试:

select  *
from    tbl t
where   name =  (  select   name
                   from     tbl
                   where    billnumber = 100756 -- can be any of his
                )
    and date =  (  select   max(date)
                   from     tbl x
                   where    x.name = t.name
                )

账单号码可以是他的任何一个

你的问题真的没有意义。你为什么要那张唱片?