Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:27:44+00:00 2026-05-22T17:27:44+00:00

I have a query like this in Postgres: select sum(ATD_AMOUNT) AS CREDIT_SUM, 0 AS

  • 0

I have a query like this in Postgres:

select sum("ATD_AMOUNT") AS CREDIT_SUM, 0 AS DEBIT_SUM,"ATD_ACCOUNT_MST_ID","AAD_OPEN_AMOUNT","AAM_ACCOUNT_NAME", "AAM_ACCOUNT_CODE" ,"AAD_YEAR_ID" 
from db_accounts."ACC_TRANSACTION_DET" 
left outer join db_accounts."ACC_TRANSACTION_MST" ON "ATD_TRANSACTION_MST_ID"=    "ATM_TRANSACTION_MST_ID"
left outer join db_accounts."ACC_ACCOUNT_MST" ON "ATD_ACCOUNT_MST_ID"="AAM_ACCOUNT_MST_ID" 
left outer join db_accounts."ACC_ACCOUNT_DET" on "AAM_ACCOUNT_MST_ID"  = "AAD_ACCOUNT_MST_ID" and "AAD_YEAR_ID"=(select "AAY_YEAR_ID" from db_accounts."ACC_ACCOUNT_YEAR" where "AAY_IS_CURRENT_YEAR"=true)
where "ATM_TRANSACTION_DATE"<= $1 and "ATM_TRANSACTION_DATE">=(select "AAY_START_DATE" from db_accounts."ACC_ACCOUNT_YEAR" where "AAY_IS_CURRENT_YEAR"=true)
and "ATM_ON_REVERSE_PARENT_TRANSACTION_ID" is null and "ATM_IS_CANCELLED"=false
    and  "AAM_DEL_FLAG" =false
AND "ATD_CREDIT_DEBIT_TRANSACTION" = 'CREDIT'
GROUP BY "ATD_ACCOUNT_MST_ID","AAD_OPEN_AMOUNT","AAM_ACCOUNT_NAME", "AAM_ACCOUNT_CODE","AAD_YEAR_ID

Here the db_accounts.”ACC_TRANSACTION_DET” contains some 50 lakh records also db_accounts.”ACC_TRANSACTION_MST” has 60000 records

Now my problem is when i run this query with same database in my system i get a result but when i try in other system it does not work?

Also what i have noticed is if any one of the below conditions are removed it displays a result

"ATM_TRANSACTION_DATE"<= $1 //field in db_accounts."ACC_TRANSACTION_MST" table

"ATM_TRANSACTION_DATE">=(select "AAY_START_DATE" from db_accounts."ACC_ACCOUNT_YEAR" where "AAY_IS_CURRENT_YEAR"=true) //field in db_accounts."ACC_TRANSACTION_MST" table

"ATD_CREDIT_DEBIT_TRANSACTION" = 'CREDIT' //field in db_accounts."ACC_TRANSACTION_DET" table
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:27:45+00:00Added an answer on May 22, 2026 at 5:27 pm

    I have reformatted your query with http://www.prettysql.net:

    SELECT
     sum("ATD_AMOUNT") AS CREDIT_SUM,
     0 AS DEBIT_SUM,
     "ATD_ACCOUNT_MST_ID",
     "AAD_OPEN_AMOUNT",
     "AAM_ACCOUNT_NAME",
     "AAM_ACCOUNT_CODE",
     "AAD_YEAR_ID"
    FROM
     db_accounts."ACC_TRANSACTION_DET" LEFT OUTER JOIN db_accounts."ACC_TRANSACTION_MST"
     ON
       "ATD_TRANSACTION_MST_ID"=
       "ATM_TRANSACTION_MST_ID" LEFT OUTER JOIN db_accounts."ACC_ACCOUNT_MST" ON "ATD_ACCOUNT_MST_ID" = "AAM_ACCOUNT_MST_ID" LEFT OUTER JOIN db_accounts."ACC_ACCOUNT_DET" ON
        "AAM_ACCOUNT_MST_ID" = "AAD_ACCOUNT_MST_ID"
      AND
       "AAD_YEAR_ID"=
       (
        SELECT "AAY_YEAR_ID"
        FROM db_accounts."ACC_ACCOUNT_YEAR"
        WHERE "AAY_IS_CURRENT_YEAR"=true
       )
    WHERE
      "ATM_TRANSACTION_DATE"<=$1
     AND
      "ATM_TRANSACTION_DATE">=
      (
       SELECT "AAY_START_DATE"
       FROM db_accounts."ACC_ACCOUNT_YEAR"
       WHERE "AAY_IS_CURRENT_YEAR"=true
      )
     AND
      "ATM_ON_REVERSE_PARENT_TRANSACTION_ID" is null
     AND
      "ATM_IS_CANCELLED"=false
     AND
      "AAM_DEL_FLAG"=false
     AND
      "ATD_CREDIT_DEBIT_TRANSACTION"='CREDIT'
    GROUP BY "ATD_ACCOUNT_MST_ID","AAD_OPEN_AMOUNT","AAM_ACCOUNT_NAME","AAM_ACCOUNT_CODE","AAD_YEAR_ID
    

    It looks like you have a where clause in your query which contains $1, the pattern used in Postgresql for parameter passing.

    Try replacing it with something like ‘2011-05-25’::date, and see if it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have a query like this: SELECT t1.id, (SELECT COUNT(t2.id) FROM t2 WHERE t2.id
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
Say I have a query like this: select ((amount1 - amount2)/ amount1) as chg
I have a simple query like this: select * from mytable where id >
I have this postgres sql query: select * from stats where athlete_id = 5
I'm using Postgres and I'm trying to write a query like this: select count(*)
I have query like this: SELECT * FROM activity WHERE (((userId = 1 OR
I have query like this: SELECT `all_messages`.`user_1`, `messages`.*, `users`.`username` FROM `all_messages` JOIN `messages` ON

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.