0

我应该在这个 sql 中添加什么?在我的系统中,我有外键ID_Number.我希望只有一个ID_Number必须显示在所有ID_Numbers具有相同的.并ID_Number选择所有没有 0 的 Bill.Arrears125 或没有 0 的 Bill.Arrears521 并且 Bill.Pay_Date 必须是最新的。

我只需要显示所有ID_NumberArrears125 和 Arrears521 不等于 0 并且Pay_Date是最新的

 __________________________________________________________
|  ID   | Arrears125 | Arrears521|  Pay_Date  |  ID_Number |
 ----------------------------------------------------------
|   1   |      0     |     0     |  12-01-01  |      1     |
 ----------------------------------------------------------
|   2   |      0     |     0     |  12-01-02  |      1     |
 ----------------------------------------------------------
|   3   |      25    |     25    |  12-01-03  |      1     |
 ----------------------------------------------------------
|   4   |      0     |     0     |  12-01-01  |      2     |
 ----------------------------------------------------------
|   5   |      0     |     0     |  12-01-02  |      2     |
 ----------------------------------------------------------
|   6   |      0     |     0     |  12-01-01  |      3     |
 ----------------------------------------------------------
|   7   |      25    |     25    |  12-01-02  |      3     |
 ----------------------------------------------------------

仅查看 ID 3 和 ID 7

  $sql=mysql_query("SELECT
                        Bill.*,users.* from Bill,users
                    WHERE
                        users.ID_Number=Bill.ID_Number
                    AND
                        (Bill.Arrears125!=0 OR Bill.Arrears521!=0)
                    GROUP BY
                        Bill.ID_Number")or die(mysql_error());
4

1 回答 1

0
select str_to_date(Pay_Date,"%Y-%m-%d") as date_temp, ID_number from Bill where Appears125 != 0 and Appears521 != order by date_temp desc
于 2013-02-21T13:28:16.130 回答