Syntax error in sql Query Design - sql

I have design one query such as
Select Temp3.*
From (
(Select temp1.alletec_ce1name,temp1.employeeid, count (temp1.alletec_mifid) AS MifAssign,alletec_mifid
from (select MIF.alletec_ce1name,User1.employeeid,MIF.alletec_mifid from Filteredalletec_mif as MIF FULL OUTER JOIN FilteredSystemUser As User1 on MIF.alletec_ce1=User1.systemuserid
FULL OUTER JOIN FilteredBusinessUnit as BU ON User1.businessunitid=BU.businessunitid
where MIF.alletec_organisationname='Konica Minolta India' AND MIF.alletec_cityname ='Delhi' AND
MIF.alletec_regionname ='North' ) as temp1
Group by temp1.alletec_mifid,temp1.alletec_ce1name,temp1.employeeid ) as Temp2 Inner Join FilteredIncident As Incident On Incident.alletec_serialnomif=Temp2.alletec_mifid ) as temp3
Now the issue is it is showing the Syntax error near the first from. What can be the possible reason for that. Thanks in advance.
I have one more query, such as
with temp2 (
alletec_ce1name,
employeeid,
alletec_mifid,
alletec_cityname,
alletec_regionname
)
as(
Select temp1.alletec_ce1name,temp1.employeeid, temp1.alletec_mifid, temp1.alletec_cityname,temp1.alletec_regionname
from (select MIF.alletec_ce1name,User1.employeeid,MIF.alletec_mifid, MIF.alletec_regionname, MIF.alletec_cityname from Filteredalletec_mif as MIF FULL OUTER JOIN FilteredSystemUser As User1 on MIF.alletec_ce1=User1.systemuserid
FULL OUTER JOIN FilteredBusinessUnit as BU ON User1.businessunitid=BU.businessunitid
where MIF.alletec_organisationname='Konica Minolta India' AND (MIF.alletec_cityname ='Delhi') AND
(MIF.alletec_regionname ='North') ) as temp1
)
select temp2.alletec_ce1name,temp2.employeeid, temp2.alletec_regionname,temp2.alletec_cityname, count(alletec_mifid) as MIFASSIGN,
Incident.alletec_casecalltypename
from temp2 Left Outer join FilteredIncident As Incident On Incident.alletec_serialnomif=temp2.alletec_mifid
group by temp2.alletec_ce1name,temp2.employeeid,temp2.alletec_mifid,temp2.alletec_regionname,temp2.alletec_cityname,
Incident.alletec_casecalltypename
now as with i got one temporary table. i wish to have one more temporary table so that can incorporate my last executable table values from temp2. do have a look if u can help for either. Thanks

Count up your parentheses, I think they are mismatched.

Your query amounts to
select
*
from
(table) as temp3
This isn't valid, you can't put the parentheses there. The extra level of nesting is broken. You either need to do something like:
select
*
from
table
or something like
select
*
from (
select
*
from
table
) as temp3
Your first query can probably be simplified to:
Select
*
From (
select
MIF.alletec_ce1name,
User1.employeeid,
MIF.alletec_mifid,
count (MIF.alltec_mifid) as MifAssign
from
Filteredalletec_mif as MIF
full outer join
FilteredSystemUser As User1
on MIF.alletec_ce1 = User1.systemuserid
full outer join
FilteredBusinessUnit as BU
on User1.businessunitid=BU.businessunitid
where
MIF.alletec_organisationname = 'Konica Minolta India' AND
MIF.alletec_cityname ='Delhi' AND
MIF.alletec_regionname ='North'
group by
MIF.alletec_mifid,
MIF.alletec_ce1name,
User1.employeeid
) as temp1
Inner Join
FilteredIncident As Incident
On Incident.alletec_serialnomif = Temp1.alletec_mifid;

Related

LEFT JOIN & SUM GROUP BY

EDIT:
The result supposed to be like this:
desired result
I have this query:
SELECT DISTINCT mitarbeiter.mitarbnr, mitarbeiter.login, mitarbeiter.name1, mitarbeiter.name2
FROM vertragspos
left join vertrag_ek_vk_zuord ON vertragspos.id = vertrag_ek_vk_zuord.ek_vertragspos_id
left join mitarbeiter ON vertrag_ek_vk_zuord.anlage_mitarbnr = mitarbeiter.mitarbnr
left join vertragskopf ON vertragskopf.id = vertragspos.vertrag_id
left join
(
SELECT wkurse.*, fremdwaehrung.wsymbol
FROM wkurse
INNER join
(
SELECT lfdnr, Max(tag) AS maxTag
FROM wkurse
WHERE tag < SYSDATE
GROUP BY lfdnr
) t1
ON wkurse.lfdnr = t1.lfdnr AND wkurse.Tag = t1.maxTag
INNER JOIN fremdwaehrung ON wkurse.lfdnr = fremdwaehrung.lfdnr
) wkurse ON vertragskopf.blfdwaehrung = wkurse.lfdnr
left join
(
SELECT vertrag_ID, Sum (preis) preis, Sum (menge) menge, Sum (preis * menge / Decode (vertragskopf.zahlintervall, 1,1,2,2,3,3,4,6,5,12,1) / wkurse.kurs) vertragswert
FROM vertragspos
GROUP BY vertrag_ID
) s ON vertragskopf.id = s.vertrag_id
But I always get an error on line 21 Pos 145:
ORA-00904 WKURSE.KURS invalid identifier
The WKURSE table is supposed be joined already above, but why do I still get error?
How can I do join with all these tables?
I need to join all these tables:
Mitarbeiter, Vertragspos, vertrag_ek_vk_zuord, wkurse, fremdwaehrung, vertragskopf.
What is the right syntax? I'm using SQL Tool 1,8 b38
Thank you.
Because LEFT JOIN is executed on entire dataset, and not in row-by-row manner. So there's no wkurse.kurs available in the execution context of subquery. Since you join that tables, you can place the calculation in the top-most select statement.
EDIT:
After you edited the statement, it became clear where does vertragskopf.zahlintervall came from. But I don't know where are you going to use calculated vertragswert (now it is absent in the query), so I've put it in the result. As I'm not a SQL parser and have no idea of your tables, so I cannot check the code, but calculation now can be resolved (all the values are available in calculation context).
SELECT DISTINCT mitarbeiter.mitarbnr, mitarbeiter.login, mitarbeiter.name1, mitarbeiter.name2, s.amount / Decode (vertragskopf.zahlintervall, 1,1,2,2,3,3,4,6,5,12,1) / wkurse.kurs) vertragswert
FROM vertragspos
left join vertrag_ek_vk_zuord ON vertragspos.id = vertrag_ek_vk_zuord.ek_vertragspos_id
left join mitarbeiter ON vertrag_ek_vk_zuord.anlage_mitarbnr = mitarbeiter.mitarbnr
left join vertragskopf ON vertragskopf.id = vertragspos.vertrag_id
left join (
SELECT wkurse.*, fremdwaehrung.wsymbol
FROM wkurse
INNER join (
SELECT lfdnr, Max(tag) AS maxTag
FROM wkurse
WHERE tag < SYSDATE
GROUP BY lfdnr
) t1
ON wkurse.lfdnr = t1.lfdnr AND wkurse.Tag = t1.maxTag
INNER JOIN fremdwaehrung ON wkurse.lfdnr = fremdwaehrung.lfdnr
) wkurse ON vertragskopf.blfdwaehrung = wkurse.lfdnr
left join (
SELECT vertrag_ID, Sum (preis) preis, Sum (menge) menge, Sum (preis * menge) as amount
FROM vertragspos
GROUP BY vertrag_ID
) s ON vertragskopf.id = s.vertrag_id
Rewriting the code using WITH clause makes it much clearer than select from select.
Also get the rate on last day before today in oracle is as simple as
select wkurse.lfdnr
, max(wkurse.kurs) keep (dense_rank first order by wkurse.tag desc) as rate
from wkurse
where tag < sysdate
group by wkurse.lfdnr
One option is a lateral join:
left join lateral
(SELECT vertrag_ID, Sum(preis) as preis, Sum(menge) as menge,
Sum (preis * menge / Decode (vertragskopf.zahlintervall, 1,1,2,2,3,3,4,6,5,12,1) / wkurse.kurs) vertragswert
FROM vertragspos
GROUP BY vertrag_ID
) s
ON vertragskopf.id = s.vertrag_id

SQL Query Select from 1 table and return data based on 2 columns

I'm working on a SQL query where I have data stored in table r. Based on the columns of give or receive, I need to store the data in a temp table to then store in a new table.
Essentially, the data is pulling from 3 tables and the end goal is to get the binary code for an image and store to display in .net
I'm trying to figure out the multi select at this time
So give or receive in r equals Username in S, display all the data that pertains and get the image if employee equals employee
I've tried a good amount of code and I feel like an OR would do the trick but it doesn't seem to.
Thanks for any help you may provide.
SELECT
r.id, r.give, r.[receive], r.[type], r.[description], r.isApproved,
r.photoGive, r.photoReceive
INTO
#temp2
FROM
Intranet.dbo.Recgonize r
SELECT s.Employee, s.Username
INTO #temp3
FROM Vision7.dbo.SEUser s
SELECT p.Photo, p.Employee
INTO #temp4
FROM Vision7.dbo.EMPhoto p
SELECT *
FROM #temp2 AS a
INNER JOIN #temp3 b ON a.give = b.Username
INNER JOIN #temp4 c ON b.Employee = c.Employee
DROP TABLE #temp2
DROP TABLE #temp3
DROP TABLE #temp4
Why are you using temporary tables for this? These just make code harder to debug and maintain, more expensive to run, and more complicated to understand.
JOINs will work without temporary tables. But you do have to additional logic to get the give and receive values in separate columns, so more JOINs are necessary:
SELECT r.id, r.give, r.[receive], r.[type], r.[description],
r.isApproved, r.photoGive, r.photoReceive,
pg.Photo as give_photo, pg.Employee as give_employee,
pr.Photo as receive_photo, pr.Employee as receive_employee
FROM Intranet.dbo.Recognize r LEFT JOIN
Vision7.dbo.SEUser sg
ON r.give = sg.Username LEFT JOIN
Vision7.dbo.SEUser sr
ON r.receive = sr.Username LEFT JOIN
Vision7.dbo.EMPhoto pg
ON sg.Employee = pg.Employee LEFT JOIN
Vision7.dbo.EMPhoto pr
ON sr.Employee = pr.Employee
Try with a single script as below-
SELECT a.id,
a.give,
a.[receive],
a.[type],
a.[description],
a.isApproved,
a.photoGive,
a.photoReceive,
b.Employee,
b.Username,
c.Photo,
c.Employee
FROM Intranet.dbo.Recgonize A
INNER JOIN Vision7.dbo.SEUser B ON a.give = b.Username
INNER JOIN Vision7.dbo.EMPhoto C ON b.Employee = c.Employee;
You may want try following:
-- Include only required columns select rather than "*"
SELECT *
FROM #temp2 AS a
INNER JOIN #temp3 b ON a.give = b.Username
INNER JOIN #temp3 b2 ON a.receive = b2.Username
INNER JOIN #temp4 c ON b.Employee = c.Employee
INNER JOIN #temp4 c2 ON b2.Employee = c2.Employee
or
-- Include only required columns in select rather than "*"
SELECT *
FROM
(select r.id, r.give as UserName, r.[type], r.[description], r.isApproved, r.photoGive from #temp2
union
select r.id, r.[receive], r.[type], r.[description], r.isApproved, r.photoReceive from #temp2
) AS a
INNER JOIN #temp3 b ON a.UserName = b.Username
INNER JOIN #temp4 c ON b.Employee = c.Employee
If temp tables are NOT used for necessary need by application, same logic can work with actual tables, just replace #Temp2, #Temp3, #Temp4 with appropriate table names.

Is there a quick fix for a syntax error in my JOIN operation

I'm fairly new to sql and am probably over my head with this but I keep running into a syntax error in my join statement.
I am trying to get specific stats for a single character. I have added more parenthese to get rid of a missing operator error, and I have tried adding parenthese to only around the inner joins of the same tables. So far the join statement is the only thing throwing errors.
SELECT CHARACTER.CharacterName, CHARACTER.Alignment, INVENTORY.Equipped,
ITEMS.ItemName,
ITEMS.PhysDef, ITEMS.MDef, ITEMS.Dodge, ITEMS.Damage, ITEMS.CritMultiplier,
ITEMS.Range,
ITEMS.AttackSpeed, JOB_CHARACTER.JobLevel, RACE_CHARACTER.RacialLevel,
RACE.RaceName, RACE.Strength,
RACE.Skill, RACE.Vitality, RACE.Arcane, RACE.Spirit, RACE.Charisma,
RACE.Luck, JOB.JobName,
JOB.HP, JOB.AttackBonus, JOB.Agility, JOB.Might, JOB.SpellPower, JOB.Vital,
JOB.Nimble, JOB.Mental,
JOB.Curese, JOB.SpellCasting, JOB.ManaBase, JOB.ManaType, JOB.Ki,
SKILLS.Alchemy, SKILLS.Awareness,
SKILLS.Climb, SKILLS.Coach, SKILLS.Construction, SKILLS.Decieve,
SKILLS.DisarmMechanism,
SKILLS.DiscernTruth, SKILLS.Dishearten, SKILLS.Fly, SKILLS.Forge,
SKILLS.Gymnastics,SKILLS.Identify,
SKILLS.Leadership, SKILLS.Lore_9Realms, SKILLS.Lore_Alternative,
SKILLS.Lore_Arcane,
SKILLS.Lore_Arithmancy, SKILLS.Lore_Divine, SKILLS.Lore_Geography,
SKILLS.Lore_Nature,
SKILLS.Lore_Nobility, SKILLS.Lore_Religion, SKILLS.Lore_Spiritual,
SKILLS.Medical,
SKILLS.Performance, SKILLS.Ride, SKILLS.Steal, SKILLS.Stealth,
SKILLS.Subterfuge,
SKILLS.Swim, SKILLS.Tailor, SKILLS.UseContraption, SKILLS.Wilderness
FROM (((((((CHARACTER INNER JOIN RACE_CHARACTER ON
CHARACTER.CharacterID=RACE_CHARACTER.CharacterID)
LEFT JOIN JOB_CHARACTER ON CHARACTER.CharacterID=JOB_CHARACTER.CharacterID)
LEFT JOIN INVENTORY ON CHARACTER.CharacterID=INVENTORY.CharacterID)
INNER JOIN INVENTORY ON ITEMS.ItemID =INVENTORY.ItemID)
INNER JOIN JOB ON JOB.JobID=JOB_CHARACTER.JobID)
LEFT JOIN SKILLS ON JOB.JobID=SKILLS.JobID)
INNER JOIN RACE ON RACE.RaceID=RACE_CHARACTER.RaceID)
WHERE ((CHARACTER.CharacterID)=1) AND ((JOB.JobID)=3) AND
((RACE.RaceID)=6);
I expect this to output the stats for this single character, its name, and skills, however it is not currently outputting anything.
Your select statement is sourcing 8 fields from an ITEMS table:
SELECT
...
ITEMS.ItemName,
ITEMS.PhysDef,
ITEMS.MDef,
ITEMS.Dodge,
ITEMS.Damage,
ITEMS.CritMultiplier,
ITEMS.Range,
ITEMS.AttackSpeed,
...
However, the ITEMS table is not referenced by your from clause:
FROM
(
(
(
(
(
(
(
CHARACTER INNER JOIN RACE_CHARACTER ON
CHARACTER.CharacterID=RACE_CHARACTER.CharacterID
)
LEFT JOIN JOB_CHARACTER ON
CHARACTER.CharacterID=JOB_CHARACTER.CharacterID
)
LEFT JOIN INVENTORY ON
CHARACTER.CharacterID=INVENTORY.CharacterID
)
INNER JOIN INVENTORY ON ----------< INVENTORY table referenced twice
ITEMS.ItemID =INVENTORY.ItemID
)
INNER JOIN JOB ON
JOB.JobID=JOB_CHARACTER.JobID
)
LEFT JOIN SKILLS ON
JOB.JobID=SKILLS.JobID
)
INNER JOIN RACE ON
RACE.RaceID=RACE_CHARACTER.RaceID
)
I should imagine the SQL code should be changed to something like:
SELECT
CHARACTER.CharacterName,
CHARACTER.Alignment,
INVENTORY.Equipped,
ITEMS.ItemName,
ITEMS.PhysDef,
ITEMS.MDef,
ITEMS.Dodge,
ITEMS.Damage,
ITEMS.CritMultiplier,
ITEMS.Range,
ITEMS.AttackSpeed,
JOB_CHARACTER.JobLevel,
RACE_CHARACTER.RacialLevel,
RACE.RaceName,
RACE.Strength,
RACE.Skill,
RACE.Vitality,
RACE.Arcane,
RACE.Spirit,
RACE.Charisma,
RACE.Luck,
JOB.JobName,
JOB.HP,
JOB.AttackBonus,
JOB.Agility,
JOB.Might,
JOB.SpellPower,
JOB.Vital,
JOB.Nimble,
JOB.Mental,
JOB.Curese,
JOB.SpellCasting,
JOB.ManaBase,
JOB.ManaType,
JOB.Ki,
SKILLS.Alchemy,
SKILLS.Awareness,
SKILLS.Climb,
SKILLS.Coach,
SKILLS.Construction,
SKILLS.Decieve,
SKILLS.DisarmMechanism,
SKILLS.DiscernTruth,
SKILLS.Dishearten,
SKILLS.Fly,
SKILLS.Forge,
SKILLS.Gymnastics,
SKILLS.Identify,
SKILLS.Leadership,
SKILLS.Lore_9Realms,
SKILLS.Lore_Alternative,
SKILLS.Lore_Arcane,
SKILLS.Lore_Arithmancy,
SKILLS.Lore_Divine,
SKILLS.Lore_Geography,
SKILLS.Lore_Nature,
SKILLS.Lore_Nobility,
SKILLS.Lore_Religion,
SKILLS.Lore_Spiritual,
SKILLS.Medical,
SKILLS.Performance,
SKILLS.Ride,
SKILLS.Steal,
SKILLS.Stealth,
SKILLS.Subterfuge,
SKILLS.Swim,
SKILLS.Tailor,
SKILLS.UseContraption,
SKILLS.Wilderness
FROM
(
(
(
(
(
(
(
CHARACTER INNER JOIN RACE_CHARACTER ON
CHARACTER.CharacterID=RACE_CHARACTER.CharacterID
)
LEFT JOIN JOB_CHARACTER ON
CHARACTER.CharacterID=JOB_CHARACTER.CharacterID
)
LEFT JOIN INVENTORY ON
CHARACTER.CharacterID=INVENTORY.CharacterID
)
LEFT JOIN ITEMS ON
ITEMS.ItemID =INVENTORY.ItemID
)
LEFT JOIN JOB ON
JOB.JobID=JOB_CHARACTER.JobID
)
LEFT JOIN SKILLS ON
JOB.JobID=SKILLS.JobID
)
INNER JOIN RACE ON
RACE.RaceID=RACE_CHARACTER.RaceID
)
WHERE
CHARACTER.CharacterID = 1 AND
JOB.JobID = 3 AND
RACE.RaceID = 6
Note that I have changed a couple of the inner joins to left joins because if you use an inner join on a table which is the right of a left join (or on the left of a right join), then you will receive an ambiguous outer joins error.

SQL Script Not Joining Results

I am having an issue getting this SQL Script to join the two tables together, I can execute it and it will show the results of the first portion (AccountID, AuditDate ..etc) but it will not join to the inner select statement.
I have verified by spot checking that there is data that matches in the database.
What portion did i mess up?
Select AccountID, AuditDate, SourceVersion
From Audit
Left join (
Select A.PrinterAuditID, A.AuditID, A.SerialNr, A.PageCountTotal,a.PageCountColor, A.PageCountMono
from InvalidPrinterAudit A
where A.DeviceID = 90757
) InvalidPrinterAudit on InvalidPrinterAudit.AuditID = Audit.AuditID
There's a couple of things happening here.
One: In order to have fields in your result set, they must be included in the SELECT portion of your query:
Select AccountID, AuditDate, SourceVersion, InvalidPrinterAudit.PrinterAuditID, InvalidPrinterAudit.AuditID, InvalidPrinterAudit.SerialNr, InvalidPrinterAudit.PageCountTotal,InvalidPrinterAudit.PageCountColor, InvalidPrinterAudit.PageCountMono
From Audit
Left join (
Select A.PrinterAuditID, A.AuditID, A.SerialNr, A.PageCountTotal,a.PageCountColor, A.PageCountMono
from InvalidPrinterAudit A
where A.DeviceID = 90757
) InvalidPrinterAudit on InvalidPrinterAudit.AuditID = Audit.AuditID
Two: You don't need to have a subquery here. Subqueries are great if you need to aggregate the results from a seperate table or something, but here you can just go with a LEFT OUTER JOIN and be done with it.
Select AccountID, AuditDate, SourceVersion, InvalidPrinterAudit.PrinterAuditID, InvalidPrinterAudit.AuditID, InvalidPrinterAudit.SerialNr, InvalidPrinterAudit.PageCountTotal,InvalidPrinterAudit.PageCountColor, InvalidPrinterAudit.PageCountMono
From Audit
Left OUTER JOIN InvalidPrinterAudit
ON InvalidPrinterAudit.AuditID = Audit.AuditID
AND InvalidPrinterAudit.DeviceID = 90757
This will apply that DeviceID = 90757 filter to your InvalidPrinterAudit before the join is applied, so you'll still get all of your Audit records, and then only the InvalidPrinterAudit records for that DeviceID that matches.
You are selecting less columns in the outer query than in the inner query.
If you want them to be returned in the resultset, include them in the outer:
Select AccountID, AuditDate, SourceVersion, PrinterAuditID, SerialNr
From Audit
Left join (
Select A.PrinterAuditID, A.AuditID, A.SerialNr, A.PageCountTotal,a.PageCountColor, A.PageCountMono
from InvalidPrinterAudit A
where A.DeviceID = 90757
) InvalidPrinterAudit on InvalidPrinterAudit.AuditID = Audit.AuditID

SQL Query- Table as invalid object

I have a SQL query
Select
temp1.domainname,
temp1.employeeid,
temp1.alletec_plantcode,
temp1.name,
temp1.alletec_customerengineer1name,
temp1.alletec_cityname,
temp1.alletec_regionname,
temp1.alletec_ce1name,
temp1.alletec_casecalltypename,
count(temp1.alletec_ce1name) as TOTALMIFASSIGN ,
(select count( MIF.alletec_ce1name) from temp1 where temp1.alletec_casecalltypename='aa') as CMMIFASSIGN
from (
Select
User1.domainname,
User1.employeeid,
User1.alletec_plantcode,
BU.name,
MIF.alletec_customerengineer1name,
MIF.alletec_cityname,
MIF.alletec_regionname,
MIF.alletec_ce1name,
Incident.alletec_casecalltypename
From
FilteredSystemUser As User1 Inner Join FilteredBusinessUnit As BU ON User1.businessunitid=BU.businessunitid
Inner join Filteredalletec_mif As MIF ON MIF.alletec_ce1=User1.systemuserid
Inner join FilteredIncident As Incident On Incident.alletec_serialnomif=MIF.alletec_mifid
where MIF.alletec_ce1name='Amit Chauhan' AND MIF.alletec_cityname='Gurgaon' and MIF.alletec_regionname='North' and Incident.statecodename='Resolved'
group by User1.domainname,
User1.employeeid,
User1.alletec_plantcode,
BU.name,
MIF.alletec_cityname,
MIF.alletec_regionname,
MIF.alletec_ce1name,
MIF.alletec_customerengineer1name,
Incident.alletec_casecalltypename
) As temp1
group by
temp1.domainname,
temp1.employeeid,
temp1.alletec_plantcode,
temp1.name,
temp1.alletec_customerengineer1name,
temp1.alletec_cityname,
temp1.alletec_regionname,
temp1.alletec_ce1name,
temp1.alletec_casecalltypename
The particular query above showing the temp1 as Invalid Object in the count query as i am require to place further filtration on it. Cant we use the above query in Aggregate function. Kindly suggest the an alternative to it.
Thanks.
The problem seem to be that the table alias temp1 isn't available when the query processor tries to resolve it. One solution that should work would be to wrap the query in a common table expression (cte). I believe this will work.
Try this:
;with temp1 (
domainname, employeeid,
alletec_plantcode, name,
alletec_customerengineer1name,
alletec_cityname, alletec_regionname,
alletec_ce1name, alletec_casecalltypename
)
as (
Select
User1.domainname,
User1.employeeid,
User1.alletec_plantcode,
BU.name,
MIF.alletec_customerengineer1name,
MIF.alletec_cityname,
MIF.alletec_regionname,
MIF.alletec_ce1name,
Incident.alletec_casecalltypename
From
FilteredSystemUser As User1 Inner Join FilteredBusinessUnit As BU ON User1.businessunitid=BU.businessunitid
Inner join Filteredalletec_mif As MIF ON MIF.alletec_ce1=User1.systemuserid
Inner join FilteredIncident As Incident On Incident.alletec_serialnomif=MIF.alletec_mifid
where MIF.alletec_ce1name='Amit Chauhan' AND MIF.alletec_cityname='Gurgaon' and MIF.alletec_regionname='North' and Incident.statecodename='Resolved'
group by User1.domainname,
User1.employeeid,
User1.alletec_plantcode,
BU.name,
MIF.alletec_cityname,
MIF.alletec_regionname,
MIF.alletec_ce1name,
MIF.alletec_customerengineer1name,
Incident.alletec_casecalltypename
)
Select
temp1.domainname,
temp1.employeeid,
temp1.alletec_plantcode,
temp1.name,
temp1.alletec_customerengineer1name,
temp1.alletec_cityname,
temp1.alletec_regionname,
temp1.alletec_ce1name,
temp1.alletec_casecalltypename,
(select count(temp1.alletec_ce1name) from temp1) as TOTALMIFASSIGN
from temp1