I want to sorting the HQL with subselect
like
Select new Item (item.id, item.name, (SELECT MAX(CreatedDate) from tab) as Created)
from ItemObj item
order by Created ASC
Is that possible?
because i get a "could not execute query" error message.
Related
I have the following Hibernate HQL query:
select t from Term t join ApprovedCourse ap on t.id = ap.term.id group by t order by t desc
It's failing with the
ORA-00979: not a GROUP BY expression
error because Oracle insists that all select values be in the group by. Hibernate, of course, is hiding the various fields of the Term object from us, letting us deal with it as a Term and not Term.id. (This query works on Postgres, by the way. Postgres is more liberal about its group by requirements.)
Hibernate is producing the following SQL:
select term0_.id as id1_12_, term0_.semester_id as semester_id2_12_, term0_.year_id as year_id3_12_
from term term0_
inner join approved_course approvedco1_
on (term0_.id=approvedco1_.term_id)
group by term0_.id
order by term0_.id desc
I've tried just removing the select t from the start of the query, but then Hibernate assumes that I'm selecting both the Term and ApprovedCourse objects, and that makes things worse.
So how do I make this work in a Hibernate way?
I found that I could get what I want by replacing the group by clause with a distinct in the select clause. Here's the resulting query:
select distinct(t) from Term t join ApprovedCourse ap on t.id = ap.term.id order by t desc
I begin to work with the Canvas section in Kibana - and to retrieve data, it uses Elasticsearch SQL.
What I try to do is to retrieve the count of several values ; and I need to group certain values together - the ones that start with the same letters.
My SQL query looks like this :
SELECT
(SELECT COUNT(*) FROM logs WHERE status LIKE 'missingValue%'),
(SELECT COUNT(*) FROM logs WHERE status LIKE 'errorValue%'),
(SELECT COUNT(*) FROM logs WHERE status='exactErrorValue'),
(SELECT COUNT(*) FROM logs WHERE status='anotherExactErrorValue')
When I test this query, using SQL and a little database, it works
Now, I want to make this work inside an element of my canvas. I choose a horizontal bar chart to represent it.
This is my elasticsearch SQL query :
SELECT
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status LIKE 'missingValue%'),
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status LIKE 'errorValue%'),
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status='exactErrorValue'),
(SELECT COUNT(*) FROM "monitoring-func-*"
WHERE status='anotherExactErrorValue')
And I get this error :
{
"error": {
"message": "[essql] > Unexpected error from Elasticsearch: [unresolved_exception] Invalid call to nullable on an unresolved object ScalarSubquery[With[{}]
\\_Project[[?COUNT(?*)]]
\\_Filter[(status) REGEX (LikePattern)#5139]
\\_UnresolvedRelation[[][index=monitoring-func-*],null,Unknown index [monitoring-func-*]],5142] AS ?"
}
}
Seeing "unknown Index", I first thought that the wildcard was the problem.
But it's not, it's perfectly fine in my others Elasticsearch queries.
Is there something about the Subqueries, the multiple SELECT, that Elasticsearch SQL doesn't handle well ?
I didn't find any ressource or topics on this, but maybe I've searched the wrong way.
Depending on your Elasticsearch version, essql either doesn't support subqueries or it is very limited, here is the documentation.
I need to convert oracle SQL query to linq query, which contains "group by having distinct count" clause.
Below is the query:
select po.id from Purchaseorder po
inner join POlineitem poline
on poline.purchaseorderid=po.id
where po.id in(236604,240480,240972,242622,242929,243293,244535)
group by po.id having count(distinct poline.orderstatus)=1
Here Purchaseorder is the parent table which might have multiple lines in POlineitem table. poline.orderstatus can have specific status values like 1,2,3,4,5,6,7,8
Please help.
Try this query
int[] objlist={236604,240480,240972,242622,242929,243293,244535};
from a in Contex.Purchaseorder.where(x=>objlist.Contain(x.id))
join b in Contex.POlineitem.Distinct(x=>x.orderstatus) on a.id equals b.purchaseorderid
group item by a.id into groupedItems
let count = groupedItems.Count()
where count==1
select item.key
SELECT DISTINCT Title,
ProductDescription,
COUNT(1) as Duplicate
FROM DB_Deals
GROUP BY Title, ProductDescription
HAVING COUNT(1) > 1;
Well, if by EF, you mean making a query using LINQ to Entities...
from deal in context.DB_Deals
group deal by new { deal.Title, deal.ProductDescription } into dealGroup
where dealGroup.Count() > 1
select new {
dealGroup.Key.Title,
dealGroup.Key.ProductDescription,
Duplicate = dealGroup.Count(),
}
Assuming, context is your DbContext, and DB_Deals is your mapped table name.
See
Entity Framework T-Sql "having" Equivalent
Group By Multiple Columns
select name,
(select count(*) from products where products.category_Id=categories.Id) as productCount
from categories
session.CreateCriteria<Category>()
but whats next?
i don't even know how to search it in Google?
think of your query like
SELECT categories.Id, count(categories.Id)
FROM categories inner join products on products.category_Id=categories.Id
group by categories.Id
I think they will produce the same result.
search google for
nhibernate criteria join
and
CreateAlias