Redigeret:Den angivne store og små bogstaver fylder forespørgslen. I outputtet af den anden fejl nedenfor kan du se, at Postgres ikke kan lide store bogstaver. Det har for vane at skrive alt med små bogstaver, medmindre du tvinger med "
citater.
--fails
select a
from
(select 1 as "A") as t;
--fails
select A
from
(select 1 as "A") as t;
--works
select "A"
from
(select 1 as "A") as t;
psql:new.sql:5: ERROR: column "a" does not exist
LINE 1: select a
^
psql:new.sql:10: ERROR: column "a" does not exist
LINE 1: select A
^
A
───
1
(1 row)
select ...
timeloggedToday.date_logged "DATE_LOGGED_TODAY",
-- should be: timeloggedToday."DATE_LOGGED" "DATE_LOGGED_TODAY",
...
LEFT JOIN
(SELECT app_user.lower_user_name,
to_char(startdate, '%Y-%m-%d') AS "DATE_LOGGED",
Sum(timeworked) / 3600 "TIME_IN_HOURS",
startdate - Now() "DIFFERENCE_DAYS"
...
) timeloggedToday ON timeloggedToday.lower_user_name = users.author;
Jeg ville overveje at slippe af med store bogstaver og kurser. Det vil bare give hovedpine. Som en sidebemærkning kan du skrive den venstre join blot én gang ved at:
-- instead of enumerating each possible interval
WHERE to_char(Now() - INTERVAL '8 days', '%Y-%m-%d') < to_char(startdate, '%Y-%m-%d')
-- select the interval
now()::date - start_date as diff
-- then build up your columns like:
case(case when diff=0 then date_logged else null end) as date_logged_today
case(case when diff=1 then date_logged else null end) as date_logged_yesterday
-- and so on ...
Du kunne også lave
CASE
WHEN Ifnull(timeloggedToday.time_in_hours, 0) = 0 THEN 'No Time Logged'
WHEN timeloggedToday.time_in_hours < 3.0 THEN 'User has not logged sufficient time'
ELSE 'user has logged sufficient time'
END "STATUS_TODAY",
ind i en funktion for at slippe af med den kedelige redundans.