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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:44:11+00:00 2026-05-23T02:44:11+00:00

Imagine a table : CUST_PROMO (customer_id,PROMOTION) which is used as a mapping between every

  • 0

Imagine a table :

CUST_PROMO (customer_id,PROMOTION) which is used as a mapping between every promotion that customer have received.

select promotion, count(customer_id) as promo_size
from CUST_PROMO
group by promotion

This gets us the total number of customers in each promotion.

Now, we’ve got CUSTOMER (customer_id, PROMO_RESPONDED,PROMO_PURCHASED), which lists the customer and which promotion got the customer to respond, and which got them to purchase.

select PROMO_RESPONDED, count(customer_id) as promo_responded 
from CUSTOMER
group by PROMO_RESPONDED

select PROMO_PURCHASED,count(customer_id) as promo_responded 
from CUSTOMER 
group by PROMO_PURCHASED

This is all very self-explanatory; now I’ve got the number of people for whom each promo was successful.

But; what I’d like to end up with is [in CSV form]

PROMOTION,PROMO_SIZE,PROMO_RESPONDED,PROMO_PURCHASED,PROMO_RESPSUCCESSRATE,blah

1,100,12,5,12%,...
2,200,23,14,11.5%,...

I have no idea how to do this. I can UNION the three queries above; but that doesn’t actually result in what I want. I thought about creating an in-memory table, inserting in each promo value and then doing an update statement with a join against it to set the values each — but that’s pretty messy; and requires a new UPDATE statement for each table/select statement. I could also make a temp table per result set and then join them together; but really; who wants to do that?

I can’t think of any way of joining this data that makes any sense; since I’m dealing with aggregates.

So, at best, I need a function that, like UNION, will combine result sets, but will actually combine like columns on a key and ADD those columns rather than union which adds rows. The description makes it sound like a JOIN; but I can’t see that working.

Thanks for the help!

  • 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-23T02:44:12+00:00Added an answer on May 23, 2026 at 2:44 am
    SELECT
      cp.promotion,
      PROMO_SIZE = COUNT(*),
      PROMO_RESPONDED = COUNT(c1.customer_id),
      PROMO_PURCHASED = COUNT(c2.customer_id),
      PROMO_RESPSUCCESSRATE = COUNT(c1.customer_id) * 100.0 / COUNT(*)
    FROM CUST_PROMO cp
      LEFT JOIN CUSTOMER c1
        ON cp.customer_id = c1.customer_id AND cp.promotion = c1.PROMO_RESPONDED
      LEFT JOIN CUSTOMER c2
        ON cp.customer_id = c2.customer_id AND cp.promotion = c2.PROMO_PURCHASED
    GROUP BY cp.promotion
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
Imagine I have an function which goes through one million/billion strings and checks smth
Imagine the following tables: create table boxes( id int, name text, ...); create table
What is the best way to track changes in a database table? Imagine you
Imagine you homebrew a custom gui framework that doesn't use windows handles (compact framework,
Imagine we have a program trying to write to a particular file, but failing.
Imagine you want to animate some object on a WinForm. You setup a timer
Imagine an object you are working with has a collection of other objects associated
Imagine the scene, you're updating some legacy Sybase code and come across a cursor.

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.