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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:44:49+00:00 2026-06-15T15:44:49+00:00

I know there is an obvious answer to this question, but I’m like a

  • 0

I know there is an obvious answer to this question, but I’m like a noob trying to remember how to write queries. I have the following table structure in Postgresql:

CREATE TABLE public.table1 (
  accountid BIGINT NOT NULL, 
  rpt_start DATE NOT NULL, 
  rpt_end DATE NOT NULL, 
  CONSTRAINT table1_pkey PRIMARY KEY(accountid, rpt_start, rpt_end)
) 
WITH (oids = false);

CREATE TABLE public.table2 (
  customer_id BIGINT NOT NULL, 
  read VARCHAR(255), 
  CONSTRAINT table2 PRIMARY KEY(customer_id)
) 
WITH (oids = false);

The objective of the query is to display a result set of accountid’s, count of accountid’s in table1 and read from table2. The join is on table1.accountid = table2.customer_id.

The result set should appear as follows:

accountid     count     read
1234          2         100
1235          9         110
1236          1         91

The count column reflect the number of rows in table1 for each accountid. The read column is a value from table2 associated with the same accountid.

  • 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-15T15:44:50+00:00Added an answer on June 15, 2026 at 3:44 pm
    select accountid, "count", read
    from
        (
            select accountid, count(*) "count"
            from table1
            group by accountid
        ) t1
        inner join
        table2 t2 on t1.accountid = t2.customer_id
    order by accountid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like the answer to this question is really simple, but I really
Maybe this is a little unconventional question but I'd like to hear an answer
This seems like an obvious thing to want to do but I have pulled
Variations of this question have been asked before, but it seems like the issue
I fear there's a simple and obvious answer to this question. I need to
I'm sure there's something obvious I'm missing here, but I know that popover controls
I know there is a lot on this topic but I can't get any
I know there are a lot of questions around on this subject, but I've
Sorry for the unlearned nature of this question. If there's a simple answer, just
This question has been asked here before . The accepted answer was probably obvious

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.