Sql三表内连接?

时间:2016-05-29 10:30:40

标签: sql derby

我正在尝试在视图中加入3个表;这是我的情况:

我有一张表,其中包含Sale for Contain Sale Details for each Item 另一个销售大师所有项目的所有销售细节.. 和另一个库存明细

String query = "SELECT SALE.ITEM_CODE, SALE.ITEM_NAME, SALE.UNIT, "
            + "SALE.QNTY, SALE.AMOUNT, SALE_MASTER.LONGDATE, SALE_MASTER.BILL_NO, "
            + "SALE_MASTER.LEDGER_CODE, SALE_MASTER.LEDGER_NAME FROM SALE "
              + "INNER JOIN SALE_MASTER"
            + " ON SALE.BILL_NO = SALE_MASTER.BILL_NO SALE"
              + "INNER JOIN INVENTORY ON SALE.ITEM_CODE = INVENTORY.ITEM_CODE"
              + "WHERE  "+CATORINORG+" LIKE '%"+LIKE+"%' "
              + "AND (SALE_MASTER.LONGDATE >= " + From + " AND SALE_MASTER.LONGDATE <= " + To + ")";

是正确的方式..谢谢adv

1 个答案:

答案 0 :(得分:0)

SELECT SALE.ITEM_CODE, SALE.ITEM_NAME, SALE.UNIT, "
            + "SALE.QNTY, SALE.AMOUNT, SALE_MASTER.LONGDATE, SALE_MASTER.BILL_NO, "
            + "SALE_MASTER.LEDGER_CODE, SALE_MASTER.LEDGER_NAME FROM SALE "
            + "INNER JOIN SALE_MASTER"
            + " ON SALE.BILL_NO = SALE_MASTER.BILL_NO"
            + " INNER JOIN INVENTORY ON INVENTORY.ITEM_CODE = SALE.ITEM_CODE"
            + " WHERE  "+CATORINORG+" LIKE '%"+LIKE+"%' "
              + "AND (SALE_MASTER.LONGDATE >= " + From + " AND SALE_MASTER.LONGDATE <= " + To + ")

它为我工作