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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:40:53+00:00 2026-06-10T10:40:53+00:00

I am using postgres but I know T-SQL too so any answer anyone can

  • 0

I am using postgres but I know T-SQL too so any answer anyone can give me ill be grateful and able to make the conversion. I am trying to run a query for my company that’s a car sales company. they sell cars all over the US primarily in OR and WA. I need to come up with a report that will allow me to return sales that are new for OR and new for Wa and then the problem I’m having is the sales for all the other states that are not OR or Wa. So right now im running a union with group by where one query is for WA and the other statement is for OR. I want the results to look really simple and just have 3 rows. 1 OR 1 WA and the 3rd row all the other states combined. I cant figure out how to combine the not equal to OR or WA into one single value. Is this even possible?

Thank you for taking the time to look at this

my query will also include used sale cars but I can integrate that once I figure out how to get this problem figured out so that’s why the query has multiple unions

Here’s my query I have now:

SELECT buyerstate        AS "State", 
       Count(buyerstate) AS "Acura", 
       saletype          AS "N/U" 
FROM   lydeal 
WHERE  stocklocationid = '8' 
       AND buyerstate = 'OR' 
       AND saledate > '8/01/12' 
       AND saletype = 'N' 
GROUP  BY buyerstate, 
          stocklocationid, 
          saletype 
UNION 
SELECT buyerstate        AS "State", 
       Count(buyerstate) AS "Acura", 
       saletype          AS "N/U" 
FROM   lydeal 
WHERE  stocklocationid = '8' 
       AND buyerstate = 'OR' 
       AND saledate > '8/01/12' 
       AND saletype = 'U' 
GROUP  BY buyerstate, 
          stocklocationid, 
          saletype 
UNION 
SELECT buyerstate        AS "State", 
       Count(buyerstate) AS "Acura", 
       saletype          AS "N/U" 
FROM   lydeal 
WHERE  stocklocationid = '8' 
       AND buyerstate = 'WA' 
       AND saledate > '8/01/12' 
       AND saletype = 'N' 
GROUP  BY buyerstate, 
          stocklocationid, 
          saletype 
UNION 
SELECT buyerstate        AS "State", 
       Count(buyerstate) AS "Acura", 
       saletype          AS "N/U" 
FROM   lydeal 
WHERE  stocklocationid = '8' 
       AND buyerstate = 'WA' 
       AND saledate > '8/01/12' 
       AND saletype = 'U' 
GROUP  BY buyerstate, 
          stocklocationid, 
          saletype 
  • 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-10T10:40:55+00:00Added an answer on June 10, 2026 at 10:40 am

    Try this

    SELECT CASE WHEN buyerstate IN ('OR','Wa') THEN buyerstate ELSE 'OTHER' END   AS "State", 
       Count(buyerstate) AS "Acura", 
       saletype          AS "N/U" 
    FROM   lydeal 
    WHERE  stocklocationid = '8' 
       AND saledate > '8/01/12' 
       AND saletype = 'N' 
    GROUP  BY CASE WHEN buyerstate IN ('OR','Wa') THEN buyerstate ELSE 'OTHER' END, 
          stocklocationid, 
          saletype 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can compile but can't execute the following code with the error (using Postgres):
I'm using pyodbc and postgres. Can I alias multiple columns? Here's the description of
Where I can find startup log of of my postgres 9.1 server. I'm using
Is it possible to have the postgres database dump(pg_dump) using SQLAlchemy? i can get
I'm using Postgres and would like to make a big update query that would
I'm using Postgres and I'd like to know how to change row information within
I know I can insert an array into a Postgres database with pg_query .
Currently we warehouse our postgres db using SSIS, but there are certain things we
Can anyone help with a Postgres syntax problem? I'm trying to insert a record,
I have a standard django setup using postgres, but I also want to access

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.