sql - If this month has 28 days, find all customers with a bill date of 29, 30, or 31 -



sql - If this month has 28 days, find all customers with a bill date of 29, 30, or 31 -

i have client bill day table looking this:

create table customer_billing ( customer_name varchar(20) ,bill_day int )

with info like

'abc', 1 'def', 10 'ghi', 28 'jkl', 29 'mno', 30 'pqr', 31

every day, send bill customers bill day equal current day [i.e., where bill_day = extract(day sysdate)].

however, if customer's bill day 31, today lastly day of month contains 28, 29, or 30 days, send client bill today well.

this have far. logic works think there improve way accomplish it.

select customer_name customer_billing 1 = 1 , bill_day = (case when bill_day <= extract(day last_day(sysdate)) extract(day sysdate) when extract(day sysdate) = extract(day last_day(sysdate)) , bill_day > extract(day last_day(sysdate)) bill_day end);

is there more elegant solution?

a more concise version:

select customer_name customer_billing least(bill_day, extract(day last_day(sysdate))) = extract(day sysdate);

sql oracle

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -