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

How to remove items with certain length from array in php
PHP running multiple scripts concurrently
Laravel can't grab inputs from form to send out email
Find array key where value contains a specific value
Redirecting duplicated pages in WordPress template
Show Duplicate Values ‚Äčin Mysql
PHP SHMOP() Memory read error
How to write correct syntax for myname [closed]
getting error when try to save shipping information for user using magento 2 api
foreach with a simple variable?
SQL sub query from PHP PDO query
inserting record if count of column is less than two else not inserting into mysql
MethodNotAllowedHttpException in RouteCollection.php line 218 what can I do?
dompdf showing quesetion marks Instead of arabic characters
Wordpress Multisite - Nginx with php-fpm random 404 errors
I can't compare password from my database and the one inputted

Categories

HOME
powerbi
xcode
clearcase
long-integer
message-queue
theano
qooxdoo
google-search-console
gprs
graphql-js
specifications
selection
watch-os-3
dhcp
max-msp-jitter
tomcat8
checkout
susy-sass
boomi
adminlte
weex
workday
liferay-6.2
conda
amazon-sns
raima
ipa
math.js
miniprofiler
laravel-4.2
fatfs
substance
toad
infopath2010
steam-web-api
rust-cargo
john-the-ripper
listjs
autoencoder
code-rally
cartopy
stat
haar-classifier
httphandler
sendinput
permission-denied
reverse-dns
vesta
gcal
rightnow-crm
beeline
node-apn
asp.net-web-api-routing
gnome-terminal
word-2007
maven-release-plugin
node.js-connect
powerpoint-2013
apache-pig-grunt
xcopy
seadragon
flask-security
webgrind
godeps
fanotify
netdatacontractserializer
knife
actionpack
shoes
shell-extensions
tidyr
flurry-analytics
iodocs
windows-rt
mobile-country-code
treeline
nachos
forceclose
map
django-settings
coalesce
ember-table
form-for
bcdedit
notin
html-frames
chronometer
border-box
image-formats
websphere-6.1
system-information
prefuse
will-paginate
boost-foreach
page-curl
kernel32
3des
aptitude
mysqli-multi-query
main-method
rtti
ntruencrypt
sqlsitemapprovider
version-control-migration
jboss-mdb
rootkit

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App