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

  • SEARCH
  • Home
  • 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 8175945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:57:58+00:00 2026-06-06T22:57:58+00:00

I want to compile the data for reporting purpose, using php communicating with postgres,

  • 0

I want to compile the data for reporting purpose, using php communicating with postgres,
I have three tables

product_status:

status_code | value
------------|------
    1       |  a
    2       |  b

product_child:

code| ID | status_code
----|----|------------
 X  |  1 |   1
 X  |  2 |   1
 X  |  3 |   2
 Y  |  1 |   2
 Y  |  2 |   2
 Z  |  1 |   1

product_master:

code|description(and some other columns not relevent)
 X  |    la
 Y  |    alb
 Z  |    lab

In the end I want basically a table like this which i’ll display

    | total child | status a | status b
bla |    3        |  2       |   1
alb |    2        |  0       |   2
lab |    1        |  1       |   0

I have tried

SELECT s.value, count(s.value) 
FROM product_child p, product_status s 
WHERE
    p.product_status = s.status_code 
    and p.product_code = get_product_code('Sofa (1-seater) J805') 
group by 
    s.value

it gives we grouping for particular code but I want this flipped and appended in front of distinct product_codes

  • 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-06-06T22:58:01+00:00Added an answer on June 6, 2026 at 10:58 pm

    do you mean like this?

    select  pm.description,
            count(pc.code) total,
            count(case when ps.value = 'A' then ps.value else null end) statusA,
            count(case when ps.value = 'B' then ps.value else null end) statusB
    from    product_master pm join product_child pc on pm.code = pc.code
            join product_status ps on pm.status_code = ps.status_code
    group by pm.description
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compile C code from the Command Prompt in Windows. I have
I want to compile a batch file into an EXE file using C++. I
I want to compile a simple hello-world-style program using the Windows command line. cl
I have a class that has some data members that I want to be
I want to compile a C# class using the command line in Visual Studio.
How do you compile assembly code using Visual Studio? I want to compile and
Say I have some data which I want several kinds of. I think the
I have been working on asp.net 3.5.I want to Convert a DateTime Data from
I'm using Hibernate with Struts. I want to copy data of one table to
Hi i want to compile a code at runtime using CodeDom. The code to

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.