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

Trying to pass ajax value from php to jquery in selectize
PHP Error: T_CONSTANT_ENCAPSED_STRING [duplicate]
.htaccess Remove trailing / unless directory
Don't allow new user, if a user has already logged in
Error Fetching http headers in wsdltophp.com
function results in Notice: Undefined offset: 0 on one website but not the other
send mail in laravel 5.4 with request input
Php generated wrong format url file path after upload to server
Php PDO search string as Google or order by best match
Submitting the same value many times when the value needs to be unique
'Order by' specified order in Woocommerce shortcode
woocommerce hooks warning “function not found”
How to acces value from route in symfony2
Get Value Of Table Field
redirecting a long URL to https
How to embed this php code in html?

Categories

HOME
cocoapods
artificial-intelligence
weblogic12c
freeradius
opencv-python
workflow
couchdb
postgresql-9.4
ews
adobe
liferay-7
azure-mobile-services
kurento
sharepoint-online
gtk
spring-security-oauth2
driver
rangy
heap-dump
reselect
gmp
scheduled-tasks
parceler
gitkraken
akka-persistence
liferay-6.2
animated-gif
ratio
web-push
morris.js
npoi
pyspark-sql
miniprofiler
amazon-iam
google-play-developer-api
memory-fences
nppexec
microsoft-ui-automation
google-now
reset
distributed-caching
1wire
minikube
latexml
type-inference
xcode8.2
common-table-expression
liteide
cloudwatch
openstack-glance
sequence-diagram
htmlspecialchars
dex
rustdoc
okio
coovachilli
fragmentstatepageradapter
vaadin4spring
univocity
teensy
astropy
dnx50
fantom
vdm-sl
componentart
kefir.js
fat32
password-recovery
full-text-indexing
nachos
zend-search-lucene
meteor-collections
nodeload
usb-flash-drive
lsa
acitree
email-verification
xalan
multiscaleimage
hardcode
series-40
delphi-prism
boost-foreach
glassfish-esb
nsrangeexception
uipasteboard
startupscript
mediacontroller
android-input-method

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