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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:25:57+00:00 2026-06-15T18:25:57+00:00

So I have these specific columns that I’m working with: customer_token , merchant_id ,

  • 0

So I have these specific columns that I’m working with:
customer_token, merchant_id, merchant_category_code, and transaction_amount.

My current query is this:

SELECT customer_token, COUNT(transaction_amount), SUM(transaction_amount)
FROM transaction 
                     WHERE file_date>20121031 
                     and file_date<20121201
GROUP BY customer_token

I want add on to the above query a part where in the result, the merchant_category_code is separated into different columns based on the transaction amount in each specific merchant_category_code. A result that would look something like this:

customer_token, count(transaction_amount),sum(transaction_amount), count(transaction_amount in merchant_category_code which is ranked 1), count(transaction_amount in merchant_category_code which is ranked 2), count(transaction_amount in merchant_category_code which is ranked 3), etc…

and then this:

customer_token, count(transaction_amount),sum(transaction_amount), sum(transaction_amount in merchant_category_code which is ranked 1), sum(transaction_amount in merchant_category_code which is ranked 2), sum(transaction_amount in merchant_category_code which is ranked 3), etc…

But I’m at a loss on how to do this or if it is even at all possible.

  • 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-15T18:25:58+00:00Added an answer on June 15, 2026 at 6:25 pm

    If you know in advance what the possible values of merchant_category_code are, you can use CASE expressions:

    SELECT customer_token,
           COUNT(transaction_amount),
           SUM(transaction_amount),
           COUNT(CASE WHEN merchant_category_code = 1 THEN transaction_amount END),
           COUNT(CASE WHEN merchant_category_code = 2 THEN transaction_amount END),
           COUNT(CASE WHEN merchant_category_code = 3 THEN transaction_amount END),
           ...
           SUM(CASE WHEN merchant_category_code = 1 THEN transaction_amount END),
           SUM(CASE WHEN merchant_category_code = 2 THEN transaction_amount END),
           SUM(CASE WHEN merchant_category_code = 3 THEN transaction_amount END),
           ...
      FROM transaction 
     WHERE file_date BETWEEN 20121101 AND 20121130
     GROUP
        BY customer_token
    ;
    

    (or IF expressions, if you prefer; for documentation on both of these, see the section titled “Conditional Functions” on the page “LanguageManual+UDF” in the Hive wiki).

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

Sidebar

Related Questions

I have a query like this: Select E.ID, E.NAME, date_format( CONVERT_TZ( CONVERT_TZ( E.ST, '+00:00',
I have an html table that is displaying customer orders. One of these columns
I have a table that has several nullable integer columns. This is undesirable for
I have the following SQL query: DECLARE @MyVar datetime = '1/1/2010' SELECT @MyVar This
I have some photos in specific drive on a hard disk, these photos all
I have a webpage that has 3 file inputs. There are specific fields on
I have these 3 tables: and I'm using this code to join them together
I have these variables: boost::regex re //regular expression to use std::string stringToChange //replace this
I have one table that looks like this called survey_1: ================================================ |id | token
I have a jqGrid with only certain columns that are editable and I would

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.