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

symfony2 Get exact content from BuzzBundle response
Is there another way to implements Long Polling in PHP
Make a php a href link with variable clickable
Where can I find the controller for a magento backend module?
how to get element from this array [duplicate]
Retrieve POST values in PHP using a dynamic method [duplicate]
Insert into table doesnt work
Doctrine2 ORM - Error using getResult
Tty to count the words from mysql results with php
Sql SELECT statement inside echo
Explode Textarea and Pass IN Select Statement
chat bubbles showing earlier in the chat iOS
Forgotten password page help [PHP/HTML]
File saving to server as invalid JSON
Footer div closing early on a single web page
Install curl to php on apache server

Categories

HOME
list
xcode
shinyapps
scroll
transactions
mousemove
jersey-2.0
turbojpeg
video-streaming
gprs
save
graphql-js
tup
gtk
log4j2
lc3
solution
yeoman-generator-angular
amazon-emr
bootstrap-switch
orc
squirrel-sql
jodatime
distributed-computing
parceler
raml
social-tables
qa
fstar
marquee
annotation-processing
javax.persistence
basic-authentication
guice
cucumber-junit
android-collapsingtoolbar
creation
bean-validation
autoencoder
nsuserdefaults
macports
fastlane
cloudera-quickstart-vm
unification
django-smart-selects
widestring
assert
zend-form
supertest
brightscript
ptvs
wikimapia
rcharts
deviare
google-identity-toolkit
s-function
frame-grab
teamviewer
as3-api
myfaces
libz
cache-manifest
karma-coverage
flow-js
clarion
gflags
mathematical-expressions
jolie
tabris
storing-data
relationships
visual-c++-2012
accessory
forceclose
.htpasswd
incognito-mode
gpu-programming
boinc
yii-booster
jquery-transit
proc-open
oembed
cgrectmake
stretch
getopt-long
telerik-ajax
uitextfielddelegate
n-queens
gwt-celltable
azure-acs
mediacontroller
libxslt
outlook-2007-addin
projectpier
sqlsitemapprovider
motif
stretchblt
downloadfile
rendering-engine

Resources

Encrypt Message