2014-07-21 247 views

回答

2
SELECT 
    TO_CHAR(
    DATE_TRUNC('month', CURRENT_DATE) -- first day of current month 
     + INTERVAL '1 month'    -- first day of next month 
     - INTERVAL '1 day',    -- last day of current month 
    'DD'        -- format last day of month 
) last_day_of_month 
+1

或者,如果你想要一個整數值只是'提取物(天從...) '而不是'to_char'。 –

+1

'1個月 - 1天'也可以 – dwery

0

使用

LEFT OUTER JOIN sales_registrations FROM months

(而不是你的右連接)。這樣,您將從sales_registrations中獲取沒有連接的記錄,並且所有這些字段將具有NULL值。

如果你不希望看到的結果NULLS, 使用SUMCASE

SUM(CASE WHEN some_field_from_sales_registrations IS NOT NULL THEN 1 ELSE 0 END) as c

相關問題