SQL - Multiplying columns - sql

I cannot get this to work
SELECT PM.PMNUM, (COUNT(ROUTE_STOP.LOCATION) * JOBPLAN.JPDURATION)
FROM PM
LEFT OUTER JOIN ROUTE_STOP ON ROUTE_STOP.ROUTE = PM.ROUTE
LEFT OUTER JOIN JOBPLAN ON JOBPLAN.JPNUM = PM.JPNUM
GROUP BY PM.PMNUM

As I see your minimum missing a group by.
SELECT PM.PMNUM, (COUNT(ROUTE_STOP.LOCATION) * JOBPLAN.JPDURATION)
FROM PM
LEFT OUTER JOIN ROUTE_STOP ON ROUTE_STOP.ROUTE = PM.ROUTE
LEFT OUTER JOIN JOBPLAN ON JOBPLAN.JPNUM = PM.JPNUM
GROUP BY PM.PMNUM, JOBPLAN.JPDURATION
If this won't help you need to give further feedback what is not working?

Related

How do you work out the average of a sum function within a temp table?

I have created a temp table that lists each client's invoice(s), plus the number of days it took to pay the invoice. A client can have more than one invoice.
Instead of this, I would just like the temp table to list each client once, along with the AVERAGE number of days it took to pay all of their invoices.
Any tips on how to do this would be much appreciated.
Thanks
select
c.client_code,
b.bill_num,
b.bill_date,
ba.TRAN_DATE,
sum(datediff(Day,b.BILL_DATE, ba.TRAN_DATE)) as Days_To_Pay
into #tempG1
from blt_bill b
left outer join blt_billm bm on b.tran_uno = bm.bill_tran_uno
left outer join BLT_BILL_AMT ba on bm.BILLM_UNO = ba.BILLM_UNO
left outer join hbm_matter m on bm.matter_uno = m.matter_uno
left outer join hbm_client c on m.client_uno = c.client_uno
where b.total_bill_amt > 0.0
and bm.ar_status NOT IN ('P','X')
and ba.TRAN_TYPE in ('CR','crx')
group by c.client_code,b.bill_num,b.bill_date,ba.TRAN_DATE
select * from #tempG1
Drop Table #tempG1
I am not familiar with temp tables, but this should work (tested on a simliar scenario on MySQL8 and assuming that #tempG1 return results):
select
c.client_code,
b.bill_num,
b.bill_date,
ba.TRAN_DATE,
sum(datediff(Day,b.BILL_DATE, ba.TRAN_DATE)) as Days_To_Pay
from blt_bill b
left outer join blt_billm bm on b.tran_uno = bm.bill_tran_uno
left outer join BLT_BILL_AMT ba on bm.BILLM_UNO = ba.BILLM_UNO
left outer join hbm_matter m on bm.matter_uno = m.matter_uno
left outer join hbm_client c on m.client_uno = c.client_uno
where b.total_bill_amt > 0.0
and bm.ar_status NOT IN ('P','X')
and ba.TRAN_TYPE in ('CR','crx')
group by c.client_code,b.bill_num,b.bill_date,ba.TRAN_DATE
into #tempG1
############################
SELECT temp.client_code, AVG(temp.Days_To_Pay)
FROM (select * from #tempG1) as temp
GROUP BY temp.client_code
############################
#### Do you see results if drop? ####
Drop Table #tempG1
Note that I put #tempG1, at the bottom of your SELECT request, but might not be what want to achieve, not sure if you want to include your JOIN conditions or not.
Or you could do without temp table(including your join conditions):
SELECT temp.client_code, AVG(temp.Days_To_Pay)
(
select
c.client_code,
b.bill_num,
b.bill_date,
ba.TRAN_DATE,
sum(datediff(Day,b.BILL_DATE, ba.TRAN_DATE)) as Days_To_Pay
from blt_bill b
left outer join blt_billm bm on b.tran_uno = bm.bill_tran_uno
left outer join BLT_BILL_AMT ba on bm.BILLM_UNO = ba.BILLM_UNO
left outer join hbm_matter m on bm.matter_uno = m.matter_uno
left outer join hbm_client c on m.client_uno = c.client_uno
where b.total_bill_amt > 0.0
and bm.ar_status NOT IN ('P','X')
and ba.TRAN_TYPE in ('CR','crx')
group by c.client_code,b.bill_num,b.bill_date,ba.TRAN_DATE
) as temp
GROUP BY temp.client_code
This sounds like a simple aggregation:
select c.client_code, avg(datediff(Day, b.BILL_DATE, ba.TRAN_DATE)) as Days_To_Pay
from blt_bill b join
blt_billm bm
on b.tran_uno = bm.bill_tran_uno join
BLT_BILL_AMT ba
on bm.BILLM_UNO = ba.BILLM_UNO join
hbm_matter m on bm.matter_uno = m.matter_uno join
hbm_client c
on m.client_uno = c.client_uno
where b.total_bill_amt > 0.0 and
bm.ar_status not in ('P', 'X') and
ba.TRAN_TYPE in ('CR', 'crx')
group by c.client_code;
Note that you do not need outer joins. The where clause is turning most of them into inner joins anyway. Plus, if you are aggregating by the client code, then presumably you want a non-NULL value.

Query for records count from shown rows

select lsd.lsd ,count(reading.infrastructure_id),type.infrastructure_type from public.cpreading_lsd lsd
left join cpreading_infrastructure infra on lsd.id = infra.lsd_id
left join public.cpreading_infrastructure_type type on type.id = infra.infrastructure_type_id
left join cpreading_cp_reading_entry reading on infra.id = reading.infrastructure_id
group by lsd.lsd,type.infrastructure_type
Make the query as an in-line view and select count(*) from the in-line view
Eg:
select count(*) from(
select lsd.lsd
,count(reading.infrastructure_id)
,type.infrastructure_type
from public.cpreading_lsd lsd
left join cpreading_infrastructure infra on lsd.id = infra.lsd_id
left join public.cpreading_infrastructure_type type on type.id = infra.infrastructure_type_id
left join cpreading_cp_reading_entry reading on infra.id = reading.infrastructure_id
group by lsd.lsd,type.infrastructure_type
)x

Left Join not working

I am a SQL Server beginner and so I have been using MS Access to create queries and then have been amending them for SQL Server.
I have created a query which includes a left join, which works perfectly in Access but when I copy the SQL code across to SQL Server it does not show the null values and I cannot work out why.
I want to show all of the attribute values whether they include a value or not. Can anyone help? The code is as follows:
SELECT DISTINCT
tbLease.LeaseTitle
, tbAttributeValue.AttributeTemplateDefinitionLinkID
, tbAttributeValue.Value
FROM
((((tbBusinessUnit
LEFT JOIN
tbAttributeValue ON tbBusinessUnit.BusinessUnitID = tbAttributeValue.ParentID)
INNER JOIN
tbBuildingLinkBusinessUnit ON tbBusinessUnit.BusinessUnitID = tbBuildingLinkBusinessUnit.BusinessUnitID)
INNER JOIN
tbBuilding ON tbBuildingLinkBusinessUnit.BuildingID = tbBuilding.BuildingID)
INNER JOIN
(tbUnitLocation
INNER JOIN
tbUnit ON tbUnitLocation.UnitID = tbUnit.UnitID)
ON tbBuilding.BuildingID = tbUnitLocation.LocationID)
INNER JOIN
tbLease ON tbUnit.UnitID = tbLease.UnitID
WHERE
(((tbAttributeValue.AttributeTemplateDefinitionLinkID) = 30
Or (tbAttributeValue.AttributeTemplateDefinitionLinkID) = 31
Or (tbAttributeValue.AttributeTemplateDefinitionLinkID) = 32));
Hard to say what you want without some examples but you might want this:
WHERE coalesce(tbAttributeValue.AttributeTemplateDefinitionLinkID,30) in (30,31,32);
This will give you items where AttributeTemplateDefinitionLinkID is null
(that is it did not join on the left join) OR is one of those 3 values.
Right now if you don't join with the left join it will not display that row because of the where condition, so your left join is the same as an inner join.
The NULL values you would normally see with a left join are getting filtered out by your WHERE clause.
Any time you add filters to a WHERE clause that apply to an outer joined table, it will effectively make it the same as an inner join unless you include NULL values as an option in your where clause as well.
SELECT DISTINCT
tbLease.LeaseTitle,
tbAttributeValue.AttributeTemplateDefinitionLinkID,
tbAttributeValue.Value
FROM
tbBusinessUnit
LEFT JOIN tbAttributeValue ON tbBusinessUnit.BusinessUnitID = tbAttributeValue.ParentID
INNER JOIN tbBuildingLinkBusinessUnit ON tbBusinessUnit.BusinessUnitID = tbBuildingLinkBusinessUnit.BusinessUnitID
INNER JOIN tbBuilding ON tbBuildingLinkBusinessUnit.BuildingID = tbBuilding.BuildingID
INNER JOIN tbUnitLocation ON tbBuilding.BuildingID = tbUnitLocation.LocationID
INNER JOIN tbUnit ON tbUnitLocation.UnitID = tbUnit.UnitID
INNER JOIN tbLease ON tbUnit.UnitID = tbLease.UnitID
WHERE
tbAttributeValue.AttributeTemplateDefinitionLinkID in (30, 31, 32)
or tbAttributeValue.AttributeTemplateDefinitionLinkID is null
Move the right table filters from where clause to ON condition when you are using Left Outer Join else Left join will be implicitly converted to INNER JOIN. Try this
SELECT DISTINCT tblease.leasetitle,
tbattributevalue.attributetemplatedefinitionlinkid,
tbattributevalue.value
FROM tbbusinessunit
LEFT JOIN tbattributevalue
ON tbbusinessunit.businessunitid = tbattributevalue.parentid
AND ( tbattributevalue.attributetemplatedefinitionlinkid IN
( 30, 31, 32 )
OR tbattributevalue.attributetemplatedefinitionlinkid IS
NULL )
INNER JOIN tbbuildinglinkbusinessunit
ON tbbusinessunit.businessunitid =
tbbuildinglinkbusinessunit.businessunitid
INNER JOIN tbbuilding
ON tbbuildinglinkbusinessunit.buildingid = tbbuilding.buildingid
INNER JOIN tbunitlocation
ON tbbuilding.buildingid = tbunitlocation.locationid
INNER JOIN tbunit
ON tbunitlocation.unitid = tbunit.unitid
INNER JOIN tblease
ON tbunit.unitid = tblease.unitid

sum of particular column getting error [duplicate]

This question already has answers here:
Reason for Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [duplicate]
(4 answers)
Closed 4 years ago.
I have a query like this:
SELECT DISTINCT
dbo.T_Order_Header.F_Exhibitor,
dbo.T_Order_Header.F_Exhibition,
dbo.T_Exhibition.F_Exhibition_Name,
dbo.T_Exhibitor.F_Exhibitor_Name,
dbo.T_Order_Detail.F_ItemCode,
dbo.T_L2Category.F_L2Cat_Name,
SUM(dbo.T_Order_Detail.F_Qty-dbo.T_Order_Detail.F_CNQty) AS F_Qty,
dbo.T_L1Category.F_L1Cat_Name,
dbo.T_Order_Header.F_Stand,
dbo.T_Category.F_Cat_name,
dbo.T_ExStand.F_Bld_Code,
dbo.T_ExBuilding.F_Bld_name
FROM dbo.T_Order_Header
LEFT OUTER JOIN dbo.T_OrderAttachment
ON dbo.T_OrderAttachment.F_OrderNumber = dbo.T_Order_Header.F_OrderNumber
LEFT OUTER JOIN dbo.T_Order_Detail
ON dbo.T_Order_Detail.[Header_ID] = dbo.T_Order_Header.[ID]
LEFT OUTER JOIN dbo.T_L2Category
ON dbo.T_Order_Detail.F_ItemCode = dbo.T_L2Category.F_ItemCode
LEFT OUTER JOIN dbo.T_L1Category
ON dbo.T_L1Category.F_L1Cat_Code = dbo.T_L2Category.F_L1Cat_Code
LEFT OUTER JOIN dbo.T_Category
ON dbo.T_Category.F_Cat_Code = dbo.T_L2Category.F_Cat_Code
LEFT OUTER JOIN dbo.T_ExStand
ON dbo.T_ExStand.F_Stand_Code = dbo.T_Order_Header.F_Stand
LEFT OUTER JOIN dbo.T_ExBuilding
ON dbo.T_ExStand.F_Bld_Code = dbo.T_ExBuilding.F_Bld_Code
LEFT OUTER JOIN dbo.T_Exhibition
ON dbo.T_Order_Header.F_Exhibition = dbo.T_Exhibition.F_Exhibition_Code
LEFT OUTER JOIN dbo.T_Exhibitor
ON dbo.T_Order_Header.F_Exhibitor = dbo.T_Exhibitor.F_Exhibitor_Code
WHERE
F_Stand IN(
SELECT F_Stand_Code
FROM T_ExStand
WHERE
F_Site_Code ='DWTC'
AND F_Bld_Code = 'HALL1-4 & CONCOURSE'
)
AND T_Order_Header.F_Exhibition = '12004'
AND T_Order_Header.F_IsActive = 1
AND F_Exhibitor='2467'
I want to show sum of F_qty but I keep getting this error:
Column 'dbo.T_Order_Header.F_Exhibitor' is invalid in the select list
because it is not contained in either an aggregate function or the
GROUP BY clause
You need to group by with all the columns which you're selecting (other than the one which is in the aggregate function), something like below query:
SELECT
dbo.T_Order_Header.F_Exhibitor,
dbo.T_Order_Header.F_Exhibition,
dbo.T_Exhibition.F_Exhibition_Name,
dbo.T_Exhibitor.F_Exhibitor_Name,
dbo.T_Order_Detail.F_ItemCode,
dbo.T_L2Category.F_L2Cat_Name,
SUM(dbo.T_Order_Detail.F_Qty-dbo.T_Order_Detail.F_CNQty) AS F_Qty,
dbo.T_L1Category.F_L1Cat_Name,
dbo.T_Order_Header.F_Stand,
dbo.T_Category.F_Cat_name,
dbo.T_ExStand.F_Bld_Code,
dbo.T_ExBuilding.F_Bld_name
FROM dbo.T_Order_Header
LEFT OUTER JOIN dbo.T_OrderAttachment
ON dbo.T_OrderAttachment.F_OrderNumber = dbo.T_Order_Header.F_OrderNumber
LEFT OUTER JOIN dbo.T_Order_Detail
ON dbo.T_Order_Detail.[Header_ID] = dbo.T_Order_Header.[ID]
LEFT OUTER JOIN dbo.T_L2Category
ON dbo.T_Order_Detail.F_ItemCode = dbo.T_L2Category.F_ItemCode
LEFT OUTER JOIN dbo.T_L1Category
ON dbo.T_L1Category.F_L1Cat_Code = dbo.T_L2Category.F_L1Cat_Code
LEFT OUTER JOIN dbo.T_Category
ON dbo.T_Category.F_Cat_Code = dbo.T_L2Category.F_Cat_Code
LEFT OUTER JOIN dbo.T_ExStand
ON dbo.T_ExStand.F_Stand_Code = dbo.T_Order_Header.F_Stand
LEFT OUTER JOIN dbo.T_ExBuilding
ON dbo.T_ExStand.F_Bld_Code = dbo.T_ExBuilding.F_Bld_Code
LEFT OUTER JOIN dbo.T_Exhibition
ON dbo.T_Order_Header.F_Exhibition = dbo.T_Exhibition.F_Exhibition_Code
LEFT OUTER JOIN dbo.T_Exhibitor
ON dbo.T_Order_Header.F_Exhibitor = dbo.T_Exhibitor.F_Exhibitor_Code
WHERE
F_Stand IN(
SELECT F_Stand_Code
FROM T_ExStand
WHERE
F_Site_Code ='DWTC'
AND F_Bld_Code = 'HALL1-4 & CONCOURSE'
)
AND T_Order_Header.F_Exhibition = '12004'
AND T_Order_Header.F_IsActive = 1
AND F_Exhibitor='2467'
group by dbo.T_Order_Header.F_Exhibitor,
dbo.T_Order_Header.F_Exhibition,
dbo.T_Exhibition.F_Exhibition_Name,
dbo.T_Exhibitor.F_Exhibitor_Name,
dbo.T_Order_Detail.F_ItemCode,
dbo.T_L2Category.F_L2Cat_Name,
dbo.T_L1Category.F_L1Cat_Name,
dbo.T_Order_Header.F_Stand,
dbo.T_Category.F_Cat_name,
dbo.T_ExStand.F_Bld_Code,
dbo.T_ExBuilding.F_Bld_name
Use below query for your requirement.
SELECT DISTINCT
dbo.T_Order_Header.F_Exhibitor,
dbo.T_Order_Header.F_Exhibition,
dbo.T_Exhibition.F_Exhibition_Name,
dbo.T_Exhibitor.F_Exhibitor_Name,
dbo.T_Order.F_ItemCode,
dbo.T_L2Category.F_L2Cat_Name,
T_Order.F_Qty F_Qty,
dbo.T_L1Category.F_L1Cat_Name,
dbo.T_Order_Header.F_Stand,
dbo.T_Category.F_Cat_name,
dbo.T_ExStand.F_Bld_Code,
dbo.T_ExBuilding.F_Bld_name
FROM dbo.T_Order_Header
LEFT OUTER JOIN dbo.T_OrderAttachment
ON dbo.T_OrderAttachment.F_OrderNumber = dbo.T_Order_Header.F_OrderNumber
LEFT OUTER JOIN
(select SUM(dbo.T_Order_Detail.F_Qty)-sum(dbo.T_Order_Detail.F_CNQty) AS F_Qty,
[Header_ID],F_ItemCode from
dbo.T_Order_Detail
group by
[Header_ID]) T_Order ON dbo.T_Order.[Header_ID] = dbo.T_Order_Header.[ID]
LEFT OUTER JOIN dbo.T_L2Category
ON dbo.F_ItemCode.F_ItemCode = dbo.T_L2Category.F_ItemCode
LEFT OUTER JOIN dbo.T_L1Category
ON dbo.T_L1Category.F_L1Cat_Code = dbo.T_L2Category.F_L1Cat_Code
LEFT OUTER JOIN dbo.T_Category
ON dbo.T_Category.F_Cat_Code = dbo.T_L2Category.F_Cat_Code
LEFT OUTER JOIN dbo.T_ExStand
ON dbo.T_ExStand.F_Stand_Code = dbo.T_Order_Header.F_Stand
LEFT OUTER JOIN dbo.T_ExBuilding
ON dbo.T_ExStand.F_Bld_Code = dbo.T_ExBuilding.F_Bld_Code
LEFT OUTER JOIN dbo.T_Exhibition
ON dbo.T_Order_Header.F_Exhibition = dbo.T_Exhibition.F_Exhibition_Code
LEFT OUTER JOIN dbo.T_Exhibitor
ON dbo.T_Order_Header.F_Exhibitor = dbo.T_Exhibitor.F_Exhibitor_Code
WHERE
F_Stand IN(
SELECT F_Stand_Code
FROM T_ExStand
WHERE
F_Site_Code ='DWTC'
AND F_Bld_Code = 'HALL1-4 & CONCOURSE'
)
AND T_Order_Header.F_Exhibition = '12004'
AND T_Order_Header.F_IsActive = 1
AND F_Exhibitor='2467'
You are using SQL group function. In this case you have to add GROUP BY clause at the end of the sql-statement. Please add all generic columns to GROUP BY clause except F_Qty. And remove DISTINCT from your select statement.

FULL OUTER JOIN in oracle

I just noticed FULL OUTER JOIN is not working in Oracle.
Other queries work fine but when I fire the query with Full outer join, it takes time and gets disconnected throwing the error.
ORA-03113: end-of-file on communication channel
RIGHT OUTER JOIN and LEFT OUTER JOIN works fine.
What can be alternative for the query below where I am using full outer join to get all records ?
select * from
(
select
FTM_OFFICE_ID,
NVL(SUM(FTD_NRS_AMOUNT),0) as TOTAL
from FMS_TRANS_DTL
inner join FMS_TRANS_MST ON FMS_TRANS_MST.FTM_TRANS_MST_ID = FMS_TRANS_DTL.FTD_TRANS_MST_ID
inner join FMS_FC_VOUCHER_CONFIG ON FMS_FC_VOUCHER_CONFIG.FFVC_VOUCHER_ID = FMS_TRANS_MST.FTM_VOUCHER_ID
where FFVC_ACCOUNT_TYPE = 3 and FTM_FISCAL_YEAR='2066/67'
and FTD_ACC_ID in (select distinct FDP_DHARAUTI_C_ACC_ID from FMS_DHARAUTI_PARAMETER where FDP_FISCAL_YEAR='2066/67' )
/*and FTD_ACC_ID in (591)*/
group by FTM_OFFICE_ID
) T1
full outer join
(
select
FTM_OFFICE_ID,
NVL(SUM(FTD_NRS_AMOUNT),0) as TOTAL
from FMS_TRANS_DTL
inner join FMS_TRANS_MST ON FMS_TRANS_MST.FTM_TRANS_MST_ID = FMS_TRANS_DTL.FTD_TRANS_MST_ID
inner join FMS_FC_VOUCHER_CONFIG ON FMS_FC_VOUCHER_CONFIG.FFVC_VOUCHER_ID = FMS_TRANS_MST.FTM_VOUCHER_ID
where FFVC_ACCOUNT_TYPE = 3 and FTM_FISCAL_YEAR='2066/67'
/*and FTD_ACC_ID in (592)*/
and FTD_ACC_ID in
(select distinct FDP_DHARAUTI_L_ACC_ID from FMS_DHARAUTI_PARAMETER where FDP_FISCAL_YEAR='2066/67' )
group by FTM_OFFICE_ID
) T2
on T1.FTM_OFFICE_ID=T2.FTM_OFFICE_ID
/*
The no. of rows that T1 can have can be different that no. of rows T2 can have.
Its not necessary any OFFICE_ID must have amount under any FTD_ACC_ID.
*/
Just noticed that if I remove the sub query in condition for FTD_ACC_ID, the query runs perfectly. Why ?
workaround based on your query + followup comments is:
alter session set "_optimizer_cost_based_transformation"=off;
eg:
SQL> alter session set "_optimizer_cost_based_transformation"=off;
Session altered.
or in the sql as a hint
/*+ opt_param('_optimizer_cost_based_transformation', 'off')
eg
select /*+ opt_param('_optimizer_cost_based_transformation', 'off') */ * from
(
select FTM_OFFICE_ID,
you're possibly hitting bug:
BUG 4204383: ORA-7445[KKQTNLOCBK] USING QUERY WITH SUBQUERY AND FULL OUTER JOIN
which has patched available only on 10.2.0.2 onwards (fixed fully in 10.2.0.4).
FULL OUTER JOIN is supported just fine in Oracle.
The error you're experiencing sounds like an Oracle bug, or possible some form of corruption. You should find an error recorded in the alert.log whenever an ORA-03113 occurs.
Typically if you receive this error it's because the background oracle system process for that session has died (which is almost always due to an Oracle internal error).
This is a problem for your friendly local DBA.
If indeed (for whatever reason) a full outer join doesn't work for you, use
-- all rows present in both t1 and t2
select * from t1 inner join t2
union all
-- all rows present in t1 but not in t2
select * from t1 left outer join t2 where t2.pk is null
union all
-- all rows present in t2 but not in t1
select * from t1 right outer join t2 where t1.pk is null
instead of
select * from t1 full outer join t2
This will return the same result.
You can try this query:
SELECT
FTM_OFFICE_ID,
NVL(SUM(FTD_NRS_AMOUNT),0) AS TOTAL
FROM FMS_TRANS_DTL
INNER JOIN FMS_TRANS_MST ON FMS_TRANS_MST.FTM_TRANS_MST_ID = FMS_TRANS_DTL.FTD_TRANS_MST_ID
INNER JOIN FMS_FC_VOUCHER_CONFIG ON FMS_FC_VOUCHER_CONFIG.FFVC_VOUCHER_ID = FMS_TRANS_MST.FTM_VOUCHER_ID
WHERE FFVC_ACCOUNT_TYPE = 3 AND FTM_FISCAL_YEAR='2066/67'
AND FTD_ACC_ID IN (
SELECT DISTINCT FDP_DHARAUTI_C_ACC_ID FROM FMS_DHARAUTI_PARAMETER WHERE FDP_FISCAL_YEAR='2066/67'
UNION
SELECT DISTINCT FDP_DHARAUTI_L_ACC_ID FROM FMS_DHARAUTI_PARAMETER WHERE FDP_FISCAL_YEAR='2066/67'
)
GROUP BY FTM_OFFICE_ID
Looks like the only thing different is separate totals for FTD_ACC_ID values of 105 and 110. One approach would be to use CASE statements to total those separately.
select
FTM_OFFICE_ID,
NVL(SUM(CASE FTD_ACC_ID WHEN 105 THEN FTD_NRS_AMOUNT ELSE 0 END),0) as TOTAL_105,
NVL(SUM(CASE FTD_ACC_ID WHEN 110 THEN FTD_NRS_AMOUNT ELSE 0 END),0) as TOTAL_110,
from FMS_TRANS_DTL
inner join FMS_TRANS_MST ON FMS_TRANS_MST.FTM_TRANS_MST_ID = FMS_TRANS_DTL.FTD_TRANS_MST_ID
inner join FMS_FC_VOUCHER_CONFIG ON FMS_FC_VOUCHER_CONFIG.FFVC_VOUCHER_ID = FMS_TRANS_MST.FTM_VOUCHER_ID
where FFVC_ACCOUNT_TYPE = 3 and FTM_FISCAL_YEAR='2066/67'
and FTD_ACC_ID in (105,110)
group by FTM_OFFICE_ID
Use UNION instead of FULL OUTER JOIN in your query like this
select * from
(
select
FTM_OFFICE_ID,
NVL(SUM(FTD_NRS_AMOUNT),0) as TOTAL
from FMS_TRANS_DTL
inner join FMS_TRANS_MST ON FMS_TRANS_MST.FTM_TRANS_MST_ID = FMS_TRANS_DTL.FTD_TRANS_MST_ID
inner join FMS_FC_VOUCHER_CONFIG ON FMS_FC_VOUCHER_CONFIG.FFVC_VOUCHER_ID = FMS_TRANS_MST.FTM_VOUCHER_ID
where FFVC_ACCOUNT_TYPE = 3 and FTM_FISCAL_YEAR='2066/67'
and FTD_ACC_ID = 105
group by FTM_OFFICE_ID ) T1 union (select FTM_OFFICE_ID,
NVL(SUM(FTD_NRS_AMOUNT),0) as TOTAL
from FMS_TRANS_DTL
inner join FMS_TRANS_MST ON FMS_TRANS_MST.FTM_TRANS_MST_ID = FMS_TRANS_DTL.FTD_TRANS_MST_ID
inner join FMS_FC_VOUCHER_CONFIG ON FMS_FC_VOUCHER_CONFIG.FFVC_VOUCHER_ID = FMS_TRANS_MST.FTM_VOUCHER_ID
where FFVC_ACCOUNT_TYPE = 3 and FTM_FISCAL_YEAR='2066/67'
and FTD_ACC_ID = 110
group by FTM_OFFICE_ID )T2