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

If session exists redirect to other page PHP
Where should i look for Yii2 log exception file
PHPMailer $mail->Send() causing white screen [duplicate]
How to upload Laravel 5.1 project on shared hosting? [duplicate]
Upload video via Laravel and ajax formdata
Search Associative Array for Key/Value Match - PHP
Parameter values results to error [duplicate]
laravel 5 validation message return some array
Laravel 5 - Add custom Helper function in Laravel 5.1 Class
Django unique URL redirection issue
PHP: File uploads with 0 filesize
Need to save cropped image from croppic to my sql database
Parsing attribute values of nested XML nodes
Can't install forked github repository via composer
Get filepath relative to Apache's document root
How do I use usort() on a multidimensional array? [duplicate]

Categories

HOME
apache-nifi
class
tomcat
applescript
bing-search
portable-class-library
hyperledger
bittorrent
clone
cisco
gtk
fbloginview
google-awareness
amazon-elb
mahout-recommender
supervisord
c#-7.0
cocos2d-android
raml
qa
rxjs5
intel
channel
restier
tracing
openbravo
android-service
marquee
tsung
mongodb-3.4
caesar-cipher
cloudera-manager
kendo-listview
cloveretl
payeezy
directfb
rails-postgresql
identify
linq.js
python-jira
jshint
roracle
nusoap
extjs4.1
sigsegv
datediff
email-forwarding
rcharts
hmmlearn
cognos-tm1
xmlbeans
mathjs
system.web.optimization
seccomp
between
groovyfx
static-methods
maximize
gwt-syncproxy
phpquery
highest
postal-code
libz
bootstrap-wysiwyg
webproject
whitespace-language
shell-extensions
nsmutabledata
incron
microsoft-expression-web
cakephp-2.2
angular-ui-select
squeezebox
.htpasswd
hyperloglog
reference-counting
property-injection
windows-taskbar
typesafe-stack
proxy-server
non-ascii-characters
sly-scroller
oscilloscope
cmath
jdom
struts2-s2hibernate
infopath-2007
differentiation
servercontrol
canonicalization
kernel32
oracle-pro-c

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile