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 6103715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:45:37+00:00 2026-05-23T13:45:37+00:00

Journal_T – Basically this is the journal table with positive and negative values. Fields

  • 0

Journal_T – Basically this is the journal table with positive and negative values.
Fields are: id, date, ref, description, amount, segment, period, year.

I want to display this in two separate columns – debits (containing positive values) and credits (containing negative values). Following is the query I am using:

$qry = mysql_query("SELECT id, date, ref, description, SUM(amount), 
                           segment, period, year
                      FROM Journal_T 
                  GROUP BY segment, year, period, id") or die(mysql_error());
  • 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-23T13:45:37+00:00Added an answer on May 23, 2026 at 1:45 pm

    If I understand the schema, do it with a CASE:

    SELECT id,
      date,
      ref,
      description,
      CASE WHEN SUM(amount) >= 0 THEN SUM(amount) ELSE NULL END AS positive,
      CASE WHEN SUM(amount) < 0 THEN SUM(amount) ELSE NULL END AS negative,
     ,segment,period,year FROM Journal_T GROUP BY segment,year,period,id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know where online copies of the old The Perl Journal articles can
I have made some code which exports some details of a journal article to
A have the document with 23 figures and 46 tables (appendix to journal article).
The following example: http://www.raddonline.com/blogs/geek-journal/iphone-sdk-uitabbarcontroller-how-to-save-user-customized-tab-order/ Doesn't work in iOS4. I would like to be able
Should journal entries be recorded in a database design? In the real world it
I have an existing journal website with the following url structure http://example.com/dbtable_id/ (eg. http://example.com/89348/)
I need to automatically download the current Wall Street Journal Prime Rate and load
Today I read a paper: O'Neill, Melissa E., The Genuine Sieve of Eratosthenes, Journal
A journal we are sending an article to is asking for the following: To
I have a message in a Journal of a Private queue (.\Private$\theQueue\Journal$) The message

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.