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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×