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

Switching from md5 to password_hash
to set custom path for image upload in ckeditor
Which kind of data structure is better? [closed]
Using “terms” and “range” filters together in Elasticsearch
How to use Regex to match PHP time() or microtime() in a string?
Magento 2 - Empty custom widget render
My redirect() function doesn't work using CodeIgniter
How to display actual data from DB
How to use php cURL on local vagrant?
Php help, remote <br /> from addresses (total php noob sorry)
Sabre PHP SOAP client
Correct way to write an IF statement but without an ENDIF?
How to add user id to another table with a submit button
Storing URL in variable
php urlencode and htmlspecialchars a variable inside started function within html <a href>
Cookie detection code not working

Categories

HOME
qt
orientdb
user-interface
android-studio
macos-sierra
generics
blast
shinyapps
windows-8.1
yahoo-weather-api
yii
redmine
operating-system
devexpress
openlayers-3
vsts-build
dronekit-python
dji-sdk
javafx-8
mailing-list
lda
solution
nexus3
business-intelligence
multi-step
webstore
sonicwall
phonegap-build
vmware-workstation
android-5.1.1-lollipop
susy-sass
parceler
neo4j.rb
perfino
quartz.net
data-collection
python-appium
strophe.js
points
ibm-connections
fatfs
region
xenapp
mapnik
windows2012
commonsware-cwac
john-the-ripper
db2-luw
spinner
nanogallery
eclipse-gmf
mv
llvm-ir
extbase
task-parallel-library
oauth2-playground
pyttsx
google-prediction
spooler
notesview
permission-denied
zend-form
intellij-lombok-plugin
return-type
aws-kinesis-firehose
sonicmq
webvtt
mongodb-aggregation
patternlab.io
msxml
deviare
msg
oci
fragmentstatepageradapter
right-to-left
node.js-connect
noclassdeffounderror
distributed-cache
voronoi
servicestack-bsd
in-app-billing
juniper-network-connect
variable-length-array
highest
screen-orientation
gluon-desktop
gitlab-omnibus
wlanapi
uitest
abstract-factory
web-api
mxe
thoughtworks-go
n-tier-architecture
smacss
igor
lync-2010
django-settings
pbkdf2
hyphen
stty
google-code-prettify
statechart
aero
days
coordinate
zend-server-ce
dynamic-c
differentiation
play2-mini
kext
anonymous-types
icicles
urchin
ixmldomdocument
levels
regioninfo
remote-working
code-camp

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App