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

Multilingual site: switching languages
jQuery hide() flicker
Cascading dropdown with jQuery
Regex to match alphanumeric characters, underscore, periods and dash, allowing dot and dash only in the middle
Setting Facebook PHP SDK access_token with setAccessToken()
How do I modify the path used by exec in php
Broken link check while initiating cron-multi
How to format `23/05/2012` into insertable value in DATETIME column?
will users see post on their wall,if a post is made on app page
Wordpress Loop passing variables
PHP Imagick - setTextEncoding() function doesn't work
Upload PHP Code not uploading image
Why create own request object? [closed]
array declration methods in php [closed]
File extension filter when choosing file to upload
Secure file storage in a server

Categories

HOME
spring-data
gaming
operating-system
kivy
plaid
whmcs
apk
mongoid
mirc
dependencies
amp
lda
csrf
tiff
jquery-select2-4
stimulsoft
tomcat8
gmp
xsl-fo
nullreferenceexception
multiple-tables
home
tableview
workday
bosun
sipp
onchange
d3.js-v4
xenapp
instructions
snap-framework
cucumber-junit
express-session
ms-dos
telephonymanager
android-n
suds
nuclio
daz3d
flume-twitter
sonarqube5.2
ssi
mobile-angular-ui
dymola
logical
qpixmap
jemdoc
distributed-cache
ioexception
nastran
dsa
auto-generate
sqlbase
gql
postal-code
tree-structure
shoes
fiware-bosun
iplimage
boolean-algebra
jchartfx
windows-taskbar
facebook-game-groups
application-server
spiral
arel
oscilloscope
oembed
xcode4.5
telerik-ajax
uipangesturerecognizer
series-40
netstream
uploading
formal-semantics
multiple-users
ppc
rtti
twitter-feed

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