0

Here is my SQL code.

I used subquery and labeled it, but when I call column from that subquery, it shows that as invalid identifier.

SELECT   TSR.Merchant_id, denomination, SUM (no_of_cards)
    FROM sales_details
   WHERE invoice_id IN (
            SELECT invoice_id
              FROM sales_header TSR
             WHERE entered_by = (
                      (SELECT account_code
                         FROM bk_dsr_account_codes
                        WHERE user_name = 'C'
                          AND PASSWORD = 'D'
                          AND mobile_no = '8994035090213391259'))
               AND entered_date BETWEEN (TO_DATE ('2013/04/01', 'yyyy/mm/dd')
                                        )
                                    AND (TO_DATE ('2013/06/30', 'yyyy/mm/dd')
                                        ))
GROUP BY denomination

error as per below

ORA-00904: "TSR"."MERCHANT_ID": invalid identifier

Please help me to sort out this issue. I need to call subquery's columns also in my final SQL view.

4

2 回答 2

3

您只能使用FROM子句中的列。所以,你的查询应该是这样的:

SELECT TSR.Merchant_id, SD.denomination, SUM (SD.no_of_cards)
  FROM sales_details SD
  JOIN sales_header TSR on SD.invoice_od = TSR.invoice_id
 WHERE entered_by = (
                  (SELECT account_code
                     FROM bk_dsr_account_codes
                    WHERE user_name = 'C'
                      AND PASSWORD = 'D'
                      AND mobile_no = '8994035090213391259'))
           AND entered_date BETWEEN (TO_DATE ('2013/04/01', 'yyyy/mm/dd')
                                    )
                                AND (TO_DATE ('2013/06/30', 'yyyy/mm/dd')
                                    )
GROUP BY SD.denomination
于 2013-06-03T06:56:29.727 回答
1
select * from table1, table2 where table1.userid=x and table2.sdsd=x

select * from table1 t1, table2 t2 where t1.userid=x and t2.sdsd=x

上面这两个输出相同...

尝试这个

SELECT   TSR.Merchant_id, denomination, SUM (no_of_cards)
    FROM sales_details,TSR
   WHERE invoice_id IN (
            SELECT invoice_id
              FROM sales_header TSR
             WHERE entered_by = (
                      (SELECT account_code
                         FROM bk_dsr_account_codes
                        WHERE user_name = 'C'
                          AND PASSWORD = 'D'
                          AND mobile_no = '8994035090213391259'))
               AND entered_date BETWEEN (TO_DATE ('2013/04/01', 'yyyy/mm/dd')
                                        )
                                    AND (TO_DATE ('2013/06/30', 'yyyy/mm/dd')
                                        ))
GROUP BY denomination
于 2013-06-03T06:59:52.477 回答