php


COALESCE(SUM(), 0) JOINED table column with GROUP BY not showing all results


I am trying to build a query that retrieves all reservations within a date timeframe and joins a payment table to calculate total payments, and few other things. The query seems to work just fine except it is leaving out reservations that have no payments. Any help would be greatly appreciated.
SELECT
reservations.reservation_id ,
properties. NAME ,
properties.address1 AS prop_address ,
reservations.last_name ,
reservations.arrival_date ,
reservations.departure_date ,
reservations.date_created ,
reservations.contract_filename ,
reservations.contract_signed ,
reservation_payments.date_of_payment ,
(
SUM(
reservations.cleaning_fee + reservations.processing_fee + reservations.pool_heat_fee + reservations.special_fees + reservations.hoa_fees + reservations.rental_fee + reservations.taxes
) - COALESCE(
SUM(
reservation_payments.amount_paid
) ,
0
)
) AS sub_total ,
COALESCE(
SUM(
reservation_payments.amount_paid
) ,
0
) AS total_paid_to_date ,
reservations.balance_due_date ,
(
SELECT
GROUP_CONCAT(
DISTINCT user_meta.first_name
ORDER BY
associated_sales_staff.display_order ASC SEPARATOR ", "
)
FROM
associated_sales_staff
JOIN user_meta ON user_meta.user_id = associated_sales_staff.user_id
WHERE
(
associated_sales_staff.reservation_id = reservations.reservation_id
)
) AS sales_agents
FROM
reservations
JOIN properties ON properties.prop_id = reservations.property_id
JOIN reservation_payments ON reservation_payments.reservation_id = reservations.reservation_id
WHERE
properties.active_for_cleaning_schedule = 1
AND reservations.arrival_date >= "2017-05-15"
AND reservations.departure_date <= "2017-05-30"
GROUP BY
reservations.reservation_id
HAVING
(sub_total >= 1)
ORDER BY
total_paid_to_date ASC

Related Links

Autoload dependencies in Laravel 5.2 package development
Given three numbers, two are guaranteed equal, find the different number. [closed]
Parsing a fixed number of XML children ordered by last using PHP
How to combine two array?
Wordpress cron don't add content to new post, but manual start working fine
Alternative to PHP $mysql->fetch_assoc()? [duplicate]
Only text on the website when i put the api
How do I install Imagemagick delegates on ubuntu
Synthesise variable length multi tonal audio with SoX while avoiding clipping
Translate variable name on Smarty foreach loop with gettext
PHP Error 'Filesize is zero bytes' when uploading image SilverStripe
PHP MYSQL JOIN error [duplicate]
Redirecting before executing commit()
display data together from 2 different SQL table
Developer forums protection, code on pages and mod_security
url_encode with WGET in PHP?

Categories

HOME
rust
oracle
ionic2
spring-data
events
automapper
eclipse-plugin
message-queue
apk
google-play-services
amp
elk-stack
azure-mobile-services
joomla3.2
pyresttest
log4j2
csrf
smartgwt
webstore
twisted
cocos2d-android
exec-maven-plugin
renderscript
multiple-tables
adminlte
bluemix-mobile-services
weex
conda
intel
perfino
sipp
animated-gif
introspection
strophe.js
xdebug
openbravo
miniprofiler
audit
intune
d3.js-v4
cucumber-junit
payeezy
des
keyboard-layout
variable-variables
utf
virtual-memory
axis
liteide
qvtkwidget
xcglogger
beeline
cordova-ios
punctuation
sequence-diagram
boost-compute
controllers
cefpython
jsonix
fragmentstatepageradapter
right-to-left
wicked-pdf
textblock
gulp-uglify
openmrs
ui4j
gdl
boost-proto
in-app-billing
place
ambiguity
mixins
featuretoggle
dbmigrate
sablecc
r.java-file
ildasm
window-resize
dmake
aho-corasick
rpg
git-reset
neo4jphp
reference-counting
hotswap
lync-2010
san
codahale-metrics
arel
examine
taskkill
server-name
series-40
mkannotation
mvcrecaptcha
zend-server-ce
filelock
botnet
airprint
anonymous-types
pyjamas
aptitude
jdownloader
principles
resharper-5.0
inversion
index.dat
levels
account-management

Resources

Encrypt Message