Hql query:
Select ecd.consumption from com.dventus.wonchi.jaxb.messages.Wonchi as w
join w.systemBound as consumption
join consumption.fixedNetwork as ecd
where w.meterId = 'DVEHighLowUsageCheck' and ecd.time in (select min(ecd.time))
Exception:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected end of subtree [Select ecd.consumption from com.dventus.wonchi.jaxb.messages.Wonchi as w join w.systemBound as consumption join consumption.fixedNetwork as ecd where w.meterId = 'DVEHighLowUsageCheck' and ecd.time in (select min(ecd.time))]
As pointed for #getjackx, the syntax is incorrect.
You need add the clause FROM for the subselect select min(ecd.time), like:
select min(ecd2.time) FROM FixedNetwork ec2
Related
Why can't I use a subquery factoring clause result in the where clause of as depicted in the following sql:
with rpt as(
select * from reports where caseid =
:case_id and rownum=1 order by created desc
)
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
where
rt.reportid = rpt.id
and
tg.gene not in('TMB','MS')
The subquery is named rptand used in the select statement's where clause. When executed encountering the following error: ORA-00904: "RPT"."ID": invalid identifier
UPDATE:
In fact nested query for the same thing is also giving me the same issue. The nested subquery is only returning a single column value from a single row:
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
where
rt.reportid = (select id from reports where caseid = :case_id and
rownum=1 order by created desc)
and
tg.gene not in('TMB','MS')
You missed to add the table rpt in your query, thus that error.
with rpt as(
select * from reports where caseid =
:case_id and rownum=1 order by created desc
)
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
join
rpt on rt.reportid = rpt.id
where
tg.gene not in('TMB','MS')
I wrote an sql update query. It is working on Mysql Workbench. I put the sql update query in laravels db update. When I am testing it with phpunit I am getting an error. The phpunit uses sqlite.
The following error appears when I run the unit test:
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 near "as": syntax error (SQL: UPDATE table1 as mainp LEFT JOIN ....)
When I am removing "as mainp" the following error appears:
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 near "LEFT": syntax error (SQL: UPDATE table1 as mainp LEFT JOIN ....)
Here is the whole update query
\DB::connection($this->dbConnection)->update(\DB::raw("
UPDATE table1 as mainp left join
(
SELECT *
FROM
(
select p.fullname, cc.surname as name_one, cc.forename as name_two
from table1 as p
LEFT JOIN table2 as cc
on p.fullname LIKE CONCAT(cc.surname,'%')
LEFT JOIN table2 as cc2
on p.fullname LIKE CONCAT('%',cc.forename)
) AS pcccc
WHERE fullname = CONCAT(name_one, name_two)
) AS main
ON mainp.fullname = main.fullname
SET mainp.name_one = main.name_one,
mainp.name_two = main.name_two")
);
All the tables are created. When I am using db::select I am getting some result.
return \DB::connection($this->dbConnection)->select(\DB::raw("select p.fullname, cc.surname as name_one, cc.forename as name_two
from table1 as p
LEFT JOIN table2 as cc
on p.fullname LIKE CONCAT(cc.surname,'%')
LEFT JOIN table2 as cc2
on p.fullname LIKE CONCAT('%',cc.forename)"));
What I am doing wrong?
I'm new to Oracle SQL, I'm being asked to do some scenarios to learn the different expressions and so on.
I'm currently working on this statement but I keep having trouble with syntax and trying to get my expressions in the correct place.
If you don't mind taking a look at what I'm doing wrong and helping me learn the correct syntax I'd appreciate it a lot.
I have to find everything in the Sale, SaleDetail, OrderStatus, Warehouse, User and StockDetail tables.
The fields I need to find are saleno, serialstart, serialend, the product description (label field), sale status (saleid (I think)), WarehouseName (WH.NAME)
Here below is the code I've written so far.
SELECT
S.SALENO,
SD.SERIALSTART,
SD.SERIALEND,
SDT.LABEL,
USR.USERNAME,
WH.NAME
FROM
ITR_SALE,
ITR_SALEDETAIL,
ITR_ORDER,
ITR_WAREHOUSE,
ITR_USER,
ITR_STOCKDETAIL
JOIN ITR_SALE S
JOIN ITR_SALEDETAIL SD ON S.ID = SD.SALENO
JOIN ITR_WAREHOUSE WH ON SD.ID = WH.NAME
JOIN ITR_ORDER ODR ON WH.ID = ODR.STATUSID
JOIN ITR_USER USR ON ODR.ID = USR.USERNAME
JOIN ITR_STOCKDETAIL ON USR.ID = SDT.LABEL
WHERE S.LASTSTATUSCHANGETIME
BETWEEN ('2016-01-01 00:00:00' AND '2016-12-31 23:59:59')
AND STATUSID = ('COMPLETED');
Below follows the error message
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 21 Column: 1
EDIT:
Finished code below, changed a few expressions and conditions.
SELECT
S.SALENO,
SD.SERIALSTART,
SD.SERIALEND,
SDA.LABEL,
USR.USERNAME,
WH.NAME
FROM
ITR_SALE S
INNER JOIN
ITR_SALEDETAIL SD ON S.ID = SD.SALEID
INNER JOIN
ITR_ORDERSTATUS ODS ON SD.ID = ODS.ID
INNER JOIN
ITR_WAREHOUSE WH ON ODS.ID = WH.NAME
INNER JOIN
ITR_USER USR ON WH.ID = USR.USERNAME
INNER JOIN
ITR_STOCKDETAIL SDA ON USR.ID = SDA.LABEL
WHERE 'DATE' BETWEEN '2016-01-01' AND '2016-12-31'
AND S.STATUSID = '4';`
Use proper join syntax. Edit. Need to remove parenthesis from last line or user IN clause.
SELECT
S.SALENO,
SD.SERIALSTART,
SD.SERIALEND,
SDT.LABEL,
USR.USERNAME,
WH.NAME
FROM
ITR_SALE S INNER JOIN ITR_SALEDETAIL SD ON S.ID = SD.SALENO
INNER JOIN ITR_SALEDETAIL SD ON S.ID = SD.SALENO
INNER JOIN ITR_WAREHOUSE WH ON SD.ID = WH.NAME
INNER JOIN ITR_ORDER ODR ON WH.ID = ODR.STATUSID
INNER JOIN ITR_USER USR ON ODR.ID = USR.USERNAME
INNER JOIN ITR_STOCKDETAIL STD ON USR.ID = SDT.LABEL
WHERE S.LASTSTATUSCHANGETIME
BETWEEN '2016-01-01 00:00:00' AND '2016-12-31 23:59:59'
AND STATUSID = 'COMPLETED';
I have written the following hive query. Here I am trying to use a column (msg) of Map data type in my join clause.
select p.p_id, count(*) from prod_json n
inner join res_pan p on n.msg["mid"] = p.id
where n.cat='XYX'
group by p.p_id limit 10;
This query always fails with error message
[Error getting row data with exception java.lang.ClassCastException:
java.lang.String cannot be cast to org.openx.data.jsonserde.json.JSONObject at
org.openx.data.jsonserde.objectinspector.JsonMapObjectInspector.getMap(Json
MapObjectInspector.java:40) at
org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:317) at
org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:353) at
org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:197) at
org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:183) at
org.apache.hadoop.hive.ql.exec.MapOperator.toErrorMessage(MapOperator.java:
529) at
org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:502) at
org.apache.hadoop.hive.ql.exec.mr.ExecMapper.map(ExecMapper.java:170) at
org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54) at
org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:453) at
I think I was able to solve the problem. I re-wrote my query as
select t2.p_id, count(*)
from (select cat, msg["mid"] as mid from prod_json) t1
join (select id, p_id from res_pan) t2
on t1.mid = t2.id
where t1.cat = 'XYZ'
group by t2.p_id
So basically don't try to use the map column directly but first platten the map into columns by using inner queries and then join on those.
This is my code after check syntax this error appear
Error at line 15, column 6: ORA-00920: invalid relational operator
What problem on this code?
SELECT ahli.mshp_no,
branch.branch_code,
branch.branch_name,
l_mshp_type.mshp_type_desc,
ahli.name,
l_idtype.description,
ahli.ic_no,
ahli.birth_date,
ahli.addr_1,
ahli.addr_2,
ahli.addr_3,
ahli.postcode,
l_state.description,
ahli.notelru,
ahli.h_phone,
ahli.hubaddr_1,
ahli.hubaddr_2,
ahli.hubaddr_3,
ahli.hubpostcode,
ahli.emp_code,
ahli.offaddr_1,
ahli.offaddr_2,
ahli.offaddr_3,
ahli.offpostcode,
ahli.offaddr_4,
waris.nama,
waris.id_type,
waris.id_no,
waris.relation,
waris.addr_1,
waris.addr_2,
waris.addr_3,
waris.postcode,
waris.addr_4,
waris.no_tel1,
waris.no_tel2,
waris.mshp_no,
ahli.mshp_type,
ahli.branch_code,
ahli.id_type,
ahli.addr_4
FROM ahli
inner join waris
ON ahli.mshp_no = waris.mshp_no
AND inner
join branch
ON ahli.branch_code = branch.branch_code
AND inner
join l_mshp_type
ON ahli.mshp_code = l_mshp_type.mshp_type_desc
AND inner
join l_idtype
ON ahli.id_type = l_idtype.description
AND inner
join l_state
ON ahli.offaddr_4 = l_state.description
INNER JOIN WARIS ON AHLI.MSHP_NO = WARIS.MSHP_NO AND
INNER JOIN
You have an extra "AND" at the end.
Remove those, just do
INNER JOIN WARIS ON AHLI.MSHP_NO = WARIS.MSHP_NO
INNER JOIN