use subquery in pgql in oracle graph server - oracle

is it possible to use subquery in PGQL code like this way?
select source, count() from
(
select a2.detination ,
a1.source,
count() as c1
from match (a1)-[e]->(a2)
group by destination, source
)group by source
having count(*)>1

Related

Oracle join select result

I 've got this problem:
I have a select statement, which is rather time consuming.
I have to join the result with itself.
I want to do something like this:
Select table1.*, table2.Consumption
from (heavy select statement) table1 left outer join
(same heavy statement) table2
on table1."id" = table2."id" and table1."Year" -1 = table2."Year"
I don't want to catch the same data 2 times. I would rather like to do something like table1 table2. Is this possible?
I need this for an application, which executes querys but isn't able to use create or something like this, otherwise i would store the data in a table.
You can use a common table expression (CTE) and materialize the results of the heavy select statement:
WITH heavy AS ( SELECT /*+ MATERIALIZE */ ... (heavy select statemenet) )
Select table1.*, table2.Consumption
from heavy table1 left outer join
heavy table2
on table1."id" = table2."id" and table1."Year" -1 = table2."Year"

ORA-00979 Not a GROUP BY Expression with complex EXTRACTVALUE

I'm trying to execute a rather simple Oracle query against a table with a XMLTYPE column:
Select POB_CODPOL, CODSIS From (
Select T1.POB_CODPOL, EXTRACTVALUE(T1.POB_XMLPOL, '/Polbas/polfun[nomfun="filterBySystem"]/extpar[codele="codsis"]/valele/text()') CODSIS
From TDTX_POLITICA_CLOB T1
Where T1.POB_CODEMP = '001840'
)
Group By POB_CODPOL, CODSIS
This throws a ORA-00979 Not a GROUP BY Expression, which I don't really understand.
Even worse: when I execute the exact same query, but with a simplified XPATH query does work:
Select POB_CODPOL, CODSIS From (
Select T1.POB_CODPOL, EXTRACTVALUE(T1.POB_XMLPOL, 'Polbas/codpol/text()') CODSIS
From TDTX_POLITICA_CLOB T1
Where T1.POB_CODEMP = '001840'
)
Group By POB_CODPOL, CODSIS
It looks like Oracle doesn't like conditions like [nomfun="filterBySystem"] when using a GROUP BY (without the grouping clause, everything works fine).
Any idea on why this can be happening?
Edit: the result of the inner query is rather simple:
EXTRACTVALUE is deprecated.
Oracle recommends to use XMLQUERY, XMLTABLE for it.
This one should work:
WITH t as
(SELECT T1.POB_CODPOL, x.CODSIS
FROM TDTX_POLITICA_CLOB T1
NATURAL JOIN XMLTABLE('/Polbas/polfun[nomfun="filterBySystem"]/extpar[codele="codsis"]/valele‌​'
PASSING POB_XMLPOL COLUMNS
CODSIS VARCHAR2(50) PATH '/') x
Where T1.POB_CODEMP = '001840')
SELECT POB_CODPOL, CODSIS
FROM t
GROUP BY POB_CODPOL, CODSIS;
There's a Bug 28588011 : "ORA-00979: NOT A GROUP BY EXPRESSION" WHEN TABLE FORMAT IS BINARY XML.
Severity 2 - Severe Loss of Service
Created 02-Sep-2018
Status 11 - Code/Hardware Bug (Response/Resolution)
WORKAROUND No
I guess they won't fix it. But the hint NO_XML_QUERY_REWRITE (that I use for other XML related bugs, too) worked for me.

How can I perform a SELECT DISTINCT on all fields except a BLOB?

I'm trying to perform a SELECT DISTINCT query in Oracle, like this:
SELECT
MOVIES.TITLE, CERTIFICATIONS.ID, PROJECTION.DAY, TIME_SLOTS.SLOT,
PROJECTION.REMAINING_SEATS, IMAGES.IMAGE
FROM
[...]
It doesn't work because the column "IMAGES.IMAGE" is a BLOB. I would like to exclude this field from the DISTINCT (because I don't need it to be unique), and I don't know how. I also tried with a GROUP BY clause, but if I try to GROUP on all the fields except the BLOB, Oracle returns this error:
ORA-00979: not a GROUP BY expression
And if I add the field in the GROUP BY clause, then Oracle returns this:
ORA-00932: inconsistent datatypes: expected - got BLOB
What can I do?
SELECT DISTINCT MOVIES.TITLE, CERTIFICATIONS.ID, PROJECTION.DAY, TIME_SLOTS.SLOT, PROJECTION.REMAINING_SEATS
FROM [...]
Distinct is applied to all columns from the SELECT list. And yes, you cannot use LOBs in GROUP BY, UNION, DISTINCT etc because Oracle doesn't know how to compare different LOBs
If you want to retrieve BLOB as well you may try something like this:
SELECT MOVIES.TITLE, CERTIFICATIONS.ID,
PROJECTION.DAY, TIME_SLOTS.SLOT, PROJECTION.REMAINING_SEATS, IMAGES.IMAGE
FROM (
SELECT MOVIES.TITLE, CERTIFICATIONS.ID,
PROJECTION.DAY, TIME_SLOTS.SLOT, PROJECTION.REMAINING_SEATS, IMAGES.IMAGE,
row_number() over (partition by MOVIES.TITLE, CERTIFICATIONS.ID, PROJECTION.DAY, TIME_SLOTS.SLOT, PROJECTION.REMAINING_SEATS
order by PROJECTION.DAY, TIME_SLOTS.SLOT) RW
FROM [...]
) WHERE RW = 1;
But you should understand what are you looking for. For example, the query above group all the columns except a BLOB column, order them by some two columns and assign a row number to each row in the group. The resulting query retrieves only the first row in each group

Vertica subquery with limit

I found problem in writing subquery with limit 1 to get the top record.
Here is my problem example.
Table Master(id,set)
Table Detail(id,set,code)
i am trying to get the latest code for each set in Master table.
Following is the query which i tried but got an error that limit 1 is not supported for correlated subqueries and it should contain GROUP By clause.
select id,set,(select code from detail where set=master.set order by id desc limit 1) from master;
And the result wolud be like
please help me if this is wrong way, i am new to this vertica database.
thnk you.
I'm not sure about that particular error, but you can use the rank() analytic function to produce results like this:
select id, set, code from (
select M.id, D.set, D.code, rank() over (partition by D.set order by D.id desc) as rank
from detail as D
right outer join master as M
on D.set = M.set) as ranks
where rank = 1
order by id;
The inner subquery uses the rank() function to assign a rank to each row within a set. The outer query just picks out rows with rank 1.

Convert oracle query to HQL by using subquery

I'm really confusing about sub Query of hibernate.
I've standard oracle query but unable to convert it into HQL.
select distinct b.nameId
from
(
select nameId from seg_user where id=1
)a, seg_user b
where b.id=a.nameId
can somebody convert it to HQL by using SubQuery or Crieteria
select distinct b.nameId
from seg_user b
where b.id = some (
select a.nameId from seg_user a where a.id=1
)
You can see how to use subqueries here: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-subqueries

Resources