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

Edit Forms PHP MySQL
yii2:drop-down list for multiple values concat in one line
SQL Error #1064 - PHP code
SQL FORM multiple tables - 'left join' vs ','
How to redirect https request to https::www
html submit button not handling action .php
Updating specific records by using a id in codeigniter
Passing $_SESSION in php
Echo a string with variable inside, getted from DB
PHP - Show more articles feature feedback
PHP Add to cart session error
How to access all values posted to PHP server
angularjs slim 404 not found for GET request
Php Mysqli questions and handler library/class
XAMPP (WAMP) server - disable accessing files outside of root directory
Tabs - Content shown after clicking one of the tab (Bootstrap)

Categories

HOME
svn
weblogic12c
apple-push-notifications
key
operating-system
compilation
message-queue
filesize
dependencies
dji-sdk
haxe
capistrano
fedora
javafx-8
u-boot
tweepy
scheduler
siesta
match
fireloop
game-maker
tiff
grocery-crud
angular4
xbap
google-awareness
global-variables
cocos2d-android
gmp
spring-ldap
yii2-basic-app
workday
altium-designer
fluent-migrator
rxjs5
perfino
uilocalnotification
tf-idf
adapter
knights-tour
cloudera-manager
devtools
custom-keyboard
spring-rabbitmq
android-canvas
grails-2.5
xerces-c
textmate2
landscape
formsauthenticationticket
ms-dos
windows-store
right-click
classnotfoundexception
hdiv
dbcc
julius-speech
moinmoin
code-push
ipp-protocol
flume-twitter
section508
cyanogenmod
sonicmq
hibernate-ogm
phppgadmin
maven-jaxb2-plugin
gtk#
popen
word-2016
cocoa-bindings
thread-exceptions
visual-studio-monaco
p6spy
nvda
tsqlt
raw-sockets
android-syncadapter
simian
facebook-ios-sdk
vaadin4spring
textblock
polymerfire
mnesia
gulp-uglify
management-studio-express
asp.net-web-api-helppages
calcite
ngcordova
swagger-maven-plugin
explain
componentart
dbmigrate
whitespace-language
camus
mathematical-expressions
baseadapter
object-code
angular-ui-select
sensormanager
eclim
revmob
rikulo
spiral
jquery-dialog
system-information
uitextfielddelegate
zotonic
firebird1.5
quartz-core
glx
git-log
uninstaller
rational-unified-process
dm
source-code-protection
word-automation

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile