Jump to content
jonnytekno

Different WHERE statements for different columns

Recommended Posts

Hi there - I am not massively proficient at SQL so get stuck with a few things

My source data contains orders (hotel bookings actually): each row has a date, value of the booking, and some other attributes e.g. channel booked through, which hotel it was etc

I want to create a table where the first column is the date (or actually the month but I can do that easily) but then it has 3 columns, each of which sums the revenue/booking value BUT in each column the selection criteria is different. For example, in column a) I only want to show the revenue for direct bookings; in column b) I want to show the revenue for travel agent bookings; in column c) I want to show all the revenue. 

I found a few other things about this where people were suggesting using CASE statements, but that only seems to work for counting unless I have missed something

Any help much appreciated

 

 

 

 

Share this post


Link to post
Share on other sites

I'm no efficient SQL user by any means. But you can use SUM in conjunction with CASE, and check from which source it comes inside it.

Here's an example: https://stackoverflow.com/questions/4517681/sql-sum-with-condition

Although this relates to SQL server and not the others, I'm sure the other versions have similar ways for using it.

Edited by Funce

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...