none
SQL multi table query - is this possible ? RRS feed

  • 問題

  • I hope it's OK for me to place my question here....

    I have 3 tables (Field name and values):

    Table "SITES"
    --------------------------------------
    SITEID
    --------------------------------------
    S1
    S2

    Table "BALANCE"
    --------------------------------------
    PRODUCTID    SITEID   QTY
    --------------------------------------
    Apple    S1   120
    Apple    S2   50
    Egg       S1    60
    Egg       S2    0

    Table "PRODUCTS"
    --------------------------------------
    PRODUCTID
    --------------------------------------
    Apple
    Egg

    How do I put together these tables and generate a recordset like:
    --------------------------------------
    PRODUCTID   S1   S2
    --------------------------------------
    APPLE    120   50
    Egg    60   0

    *having the values S1, S2 become the column name.

    I am new to SQL, please enlight me.

    Million thanks in advance.

    Peace.

    Kevin

    2009年5月4日 上午 06:56

解答

所有回覆