Code:
select hours,userN,daily,tEmail
from(
select (totalBillable - daily) as hours
,totalBillable
,userN
,daily
,tEmail
from(
select IFNULL(sumtot,0)+IFNULL(sumgen,0) + IFNULL(sumgenNB,0)+IFNULL(sumtotNB,0) as totalBillable,
userN,
daily,
tEmail
from(
select round(sum(tot),2) as sumtot
, round(sum(gen),2) as sumgen
,round(sum(genNB),2) as sumgenNB
,round(sum(totNB),2) as sumtotNB
, userN
,daily
,tEmail
from (
select sum(tech_notes.time_spent) as tot
, null as gen
, null as totNB
, null as genNB
, tech_notes.tech_notes_ticket_tech as userN
,users.dailyHours as daily
,users.tech_email as tEmail
from tech_notes
join new_tickets
on tech_notes.ticket_unique_id
= new_tickets.ticket_unique_id
join users
on users.tech_user = tech_notes.tech_notes_ticket_tech
where new_tickets.billable IS NULL
and new_tickets.ticket_status <> "new"
and tech_notes.tech_notes_real_date = '2004-12-01'
group
by tech_notes.tech_notes_ticket_tech
union
select null as tot
, null as genNB
,sum(tech_notes.time_spent) as totNB
,null as gen
, tech_notes.tech_notes_ticket_tech as userN
, users.dailyHours as daily
, users.tech_email as tEmail
from tech_notes
join new_tickets
on tech_notes.ticket_unique_id
= new_tickets.ticket_unique_id
join users
on users.tech_user = tech_notes.tech_notes_ticket_tech
where new_tickets.billable IS NOT NULL
and new_tickets.ticket_status <> "new"
and tech_notes.tech_notes_real_date = '2004-12-01'
group
by tech_notes.tech_notes_ticket_tech
union
select null as tot
, sum(generaltimesheet.hoursSpent) as gen
, null as totNB
, null as genNB
, generaltimesheet.userName as userN
, users.dailyHours as daily
, users.tech_email as tEmail
from generaltimesheet
join users
on users.tech_user = generaltimesheet.userName
where generaltimesheet.billable IS NOT NULL
and generaltimesheet.generalDate = '2004-12-01'
group by generaltimesheet.userName
union
select null as totNB
,null as tot
,null as gen
, sum(generaltimesheet.hoursSpent) as genNB
, generaltimesheet.userName as userN
, users.dailyHours as daily
,users.tech_email as tEmail
from generaltimesheet
join users
on users.tech_user = generaltimesheet.userName
where generaltimesheet.billable IS NULL
and generaltimesheet.generalDate = '2004-12-01'
group
by generaltimesheet.userName
) as newTable
group
by userN
order
by userN
) as brandNew
) as hoursTable
) as final
Any help would be greatly appreciated!
Bookmarks