Esper How To Join Tables - esper

I m sure that this statement works in Esper:
/* query from table TableA when receive event PriceEvent */
ON PriceEvent p
SELECT a.SymbolA, p.price
FROM TableA a
WHERE a.Symbol = p.Symbol
But this statement throws error:
/* join table TableA with TableB */
ON PriceEvent p
SELECT a.SymbolA, p.price, b.SymbolB
FROM TableA a, TableB b
WHERE a.Key = b.Key and a.Symbol = p.Symbol
Error Message:
com.espertech.esper.client.EPStatementSyntaxException: Incorrect syntax near ',' expecting end-of-input but found a comma ','
Then I use JOIN but it still doesn't work:
/* join table TableA with TableB */
ON PriceEvent p
SELECT a.SymbolA, p.price, b.SymbolB
FROM TableA a inner join TableB b
ON a.Key = b.Key
WHERE a.Symbol = p.Symbol
Error Message:
Incorrect syntax near 'join' (a reserved keyword) expecting end-of-input but found 'join'
How to join two tables in Esper?

The on-select only allows only a single named window or table and not multiple. Joins are just "select * from A, B, C...." and you can look into using "unidirectional".

Related

how can i use inner join in solr

SELECT A.ioTDeviceKind, B.resourceRiskLevelLowCount, B.resourceRiskLevelMiddleCount, B.resourceRiskLevelHighCount FROM ioTDevice AS A JOIN resourcelogCurrent AS B ON A.ioTDeviceKind = B.ioTDeviceKind WHERE A.resourceId = 'airconditinal'
or
SELECT A.ioTDeviceKind, B.resourceRiskLevelLowCount, B.resourceRiskLevelMiddleCount, B.resourceRiskLevelHighCount FROM ioTDevice AS A INNER JOIN resourcelogCurrent AS B ON A.ioTDeviceKind = B.ioTDeviceKind WHERE A.resourceId = 'airconditinal'
but the result is null.
there is no error, but the result always is null,
where i user left join, there is no error..
please help me , how can i use inner join in solr??

How to translate an raw SQL query to TypeORM query builder?

How would I convert the subQuery select with distinct to TypeORM querybuilder? Thanks.
SELECT `time`, (case when `start` is NULL then 0 else 1 end) `is_reserved` FROM a left join (SELECT `time` FROM b join c on c.b_id = b.id WHERE b.date = '2022-04-20') MySchedule on MySchedule.time = a.time where a.is_use = 1
a table
time
is_use
b table
id
date
c table
b_id
time
You can first build the nested query and then left-join it to the main query:
import { getConnection } from 'typeorm';
// build the nested query
const nestedQuery = getConnection()
.createQueryBuilder(B, 'b').select('time')
.innerJoin(C, 'c.b_id = b.id')
.where(`b.date = '2022-04-20'`);
getConnection().createQueryBuilder(A, 'a')
.select([
'time',
])
.addSelect('(case when `start` is NULL then 0 else 1 end)', 'is_reserved')
// left join the nested query
.leftJoin(
`(${nestedQuery.getQuery()})`,
'MySchedule',
'MySchedule.time = a.time')
.where('a.is_use = 1')
.getMany();
Where A, B and C are TypeORM entities.

select all records from left table that do not exist in right table

I am working on sql server I have two tables and I need to return records from the left table which are not found in the right table for that I am using left join like below query,
select #MID=MID,#MName=Name,#PID=PID,#PName=PName,#DID=DID from #CompanyDataInfo where id=#MCount
insert into #temp SELECT Top(1) f.Name,f.PID,f.PName,v.* FROM #CompanyDataInfo f
left join Employee v on v.Id=f.ID and v.DID=f.DID
where v.Id =#MID and v.DId = #DId and v.PId = #PId and v.CId =#CId and DATE_TIME between DATEADD(minute,-555,GETDATE()) and GETDATE() order by DATE_TIME desc
Result should be all rows from #CompanyDataInfo table while no record found in Employee table for related ID, I googled and use "v.Id is null" but not getting expected result
Is there any solution greatly appriciable
Thanks In advance
Your query is not using left join in correct way. You are using your right table reference in where clause. I try to correct it below but I don't have full information about your table schema. Please try this-
select
#MID = MID,
#MName = Name,
#PID = PID,
#PName = PName,
#DID = DID
from #CompanyDataInfo
where id = #MCount
insert into #temp
select
f.Name,
f.PID,
f.PName,
v.*
from #CompanyDataInfo f
left join Employee v on v.Id=f.ID and v.DID=f.DID
where f.Id = #MID and
f.DId = #DId and
f.PId = #PId and
f.CId = #CId and
f.DATE_TIME between DATEADD(minute,-555,GETDATE()) and GETDATE() and
v.Id is null
order by f.DATE_TIME desc
Add ...and v.Id is null to your where clause.

Sql server : How to use "NOT IN" Query in stored procedure instead of left join?

My current code snippet is given below. I want to use "NOT IN" query instead of left join.
from Complaints C
inner join Employees E on E.ID = C.EmployeeID
left join ComplaintInfractionMapping CIM on CIM.ComplaintID = C.ID
How to use "NOT IN" Query in stored procedure . In below code there is syntax error.
from Complaints C
inner join Employees E on E.ID = C.EmployeeID
NOT IN SELECT InfractionComment,InfractionDate FROM ComplaintInfractionMapping where ComplaintID = C.ID
you can do like this way :-
from Complaints C
inner join Employees E on E.ID = C.EmployeeID
Where Not Exists ( SELECT InfractionComment
,InfractionDate
FROM ComplaintInfractionMapping
where ComplaintID = C.ID
)

need to convert SQL CROSS JOIN into LINQ

I have two tables table1 and table2. Each table contains a column with itemPrice. I need to add the two columns together.
The SQL query below returns the correct SUM.
SELECT SUM(item1+ item2) FROM
(select SUM(t1.itemPrice) item1 from table1 t1 WHERE t1.userid=='jonh') tableA
CROSS JOIN
(select SUM(t2.itemPrice) item2 from table2 t2 WHERE t1.userid=='jonh') tableB
I am not been lazy but the above query has so many SUM functions that I don't know where to start to write LINQ queries.
Can anyone help?
Ceci,
Hopefully this will give you what you want...
from f in (
from x in ( from t1 in Table1
where t1.Userid.Equals("John")
select new { Userid = t1.Userid }
).Distinct()
select new { item1 = ( from z in Table1
where z.Userid.Equals("John")
select z.ItemPrice ).Sum() ??0 ,
item2 = ( from z in Table2
where z.Userid.Equals("John")
select z.ItemPrice ).Sum() ??0 }
) select new { total = f.item1 + f.item2 }
In the case where there are no records for "john" in one table, it will bring back a 0 and sum up the other tables.
hope this helps.

Resources