This is based on valid SQL but I cannot get it to work in DQL
SELECT
EXISTS (
SELECT activity FROM Entity\Activity activity
WHERE activity MEMBER OF person.activities
AND activity.name = 'sports'
) AS doesSports,
person.id
FROM Entity\Person person
This gives the error:
[Syntax Error] line 0, col 7: Error: Expected known function, got 'EXISTS'
EXISTS seems to work like this after WHERE but not in select
The grammer does not permit so-called "Other Expressions" in the SELECT clause, only functions are allowed.
Related
How do I add an INTO statement to this query? I am selecting data from two tables, when the user selects the auction (P62_AUCTION) and bidder (P62_BIDDER), display the auction_no, item_no, item_description, serial_no, and reserve_price from auc_bidding_tb b and auc_auction_list_tb l. Here is my query, I am using the new apex environment
SELECT distinct
apex_item.checkbox(1,b.item_no,'UNCHECKED') " ",
b.auction_no,
b.item_no,
l.item_description,
l.serial_no,
l.reserve_price
FROM auc_bidding_tb b, auc_auction_list_tb l
where b.auction_no = :P62_AUCTION
AND b.bidder = :P62_BIDDER
AND l.auction_no = b.auction_no
AND l.item_no = b.item_no
and l.receipt_number IS NULL;
However I an getting an error:
ORA-06550: line 1, column 64: PLS-00428: an INTO clause is expected in this SELECT statement
How do I solve this error?
The error "an INTO clause is expected in this SELECT" means your code has been executed in the PLSQL scope (between "begin" and "end") in that case you can't just query for data but you have to store it somewhere. That's why INTO clause is being expected.
The second error means the query you ran did not find any data to return, which is an exception in the PLSQL scope.
So, I see 2 options here:
Perform query within SQL scope if possible
Handle "no_data_found" exception for that case providing a more "user-friendly" message
Analyse where conditions to find out why there is no data
In hive,
I am trying to select the entry with the minimum timestamp, however it's throwing the following error, not sure what is the reason.
select * from sales where partition_batch_ts = (select max(partition_batch_ts) from sales);
Error
Error while compiling statement: FAILED: ParseException line 1:91 cannot recognize input near 'select' 'max' '(' in expression specification
I think you need to use proper table alias. Also, IN must be used instead of =
SELECT s1.*
FROM sales s1
WHERE s1.partition_batch_ts IN
(SELECT MAX(partition_batch_ts)
FROM sales s2);
From Hive manual, SUBQUERIES :
As of Hive 0.13 some types of subqueries are supported in the WHERE
clause.
I have a created a table (movies) in Hive as below(id,name,year,rating,views)
1,The Nightmare Before Christmas,1993,3.9,4568
2,The Mummy,1932,3.5,4388
3,Orphans of the Storm,1921,3.2,9062
4,The Object of Beauty,1991,2.8,6150
5,Night Tide,1963,2.8,5126
6,One Magic Christmas,1985,3.8,5333
7,Muriel's Wedding,1994,3.5,6323
8,Mother's Boys,1994,3.4,5733
9,Nosferatu: Original Version,1929,3.5,5651
10,Nick of Time,1995,3.4,5333
I want to write a hive query to get the name of the movie with highest views.
select name,max(views) from movies;
but it gives me an error
FAILED: Error in semantic analysis: Line 1:7 Expression not in GROUP BY key name
but doing a group by with name gives me the complete list (which is expected).
What changes should I make to my query?
It is very possible that there is a simpler way to do this.
select name
from(
select max(views) as views
, name
, row_number() over (order by max(views) desc) as row_num
from movies
group by name
) m
where row_num = 1
After little bit of digging, I found out that the answer is not so straightforward as we do in SQL. Below query gives the expected result.
select a.name,a.views from movies a left semi join(select max(views) views from movies)b on (a.views=b.views);
I'm looking for a way to optimize my query.
We have a table with events called lea, with a column app_properties, which are tags, stored as a comma separated string.
I would like to select all the events that match the result of a query that select the desired tags.
My first try:
SELECT uuid, app_properties, tag
FROM events
LATERAL VIEW explode(split(app_properties, '(, |,)')) tag_table AS tag
WHERE tag IN (SELECT source_value FROM mapping WHERE indicator = 'Bandwidth Usage')
But Hive will not allow this...
FAILED: SemanticException [Error 10249]: Line 4:6 Unsupported SubQuery Expression 'tag': Correlating expression cannot contain unqualified column references.
Gave it another try by replacing WHERE tag IN by WHERE tag_table.tag IN but not luck...
FAILED: SemanticException Line 4:6 Invalid table alias tag_table' in definition of SubQuery sq_1 [tag_table.tag IN (SELECT source_value FROM mapping WHERE indicator = 'Bandwidth Usage')] used as sq_1 at Line 4:20.
In the end... The query below gives the desired result, but I've a feeling that this is not the most optimized way of solving this use case. Has anyone ran into the same use case where you need the select from a LATERAL VIEW using a Sub query?
SELECT to_date(substring(events.time, 0, 10)) as date, t2.code, t2.indicator, count(1) as total
FROM events
LEFT JOIN (
SELECT distinct t.uuid, im.code, im.indicator
FROM mapping im
RIGHT JOIN (
SELECT tag, uuid
FROM events
LATERAL VIEW explode(split(app_properties, '(, |,)')) tag_table AS tag
) t
ON im.source_value = t.tag AND im.indicator = 'Bandwidth Usage'
WHERE im.source_value IS NOT NULL
) t2 ON (events.uuid = t2.uuid)
WHERE t2.code IS NOT NULL
GROUP BY to_date(substring(events.time, 0, 10)), t2.code, t2.indicator;
The Hive subquery in the WHERE clause can be used with IN, NOT IN, EXIST, or NOT
EXIST as follows. If the alias (see the following example for the employee table) is not specified before columns (name) in the WHERE condition, Hive will report the error Correlating expression cannot contain unqualified column references. This is a limitation of the Hive subquery.
From Apache Hive Essentials.
I guess this problem is also caused by subquery.
events should have an alias
Please find the below query. When I run this query I am getting an ORA-00907: missing right parenthesis error. I am unable to understand the problem on this query. Please give me the solution for this error. I have read some related topics on this topic. but, I didn't get the right solution. I am using Oracle 10g version.
The query:
SELECT A.City||'.' AS AAddress,
M_InOut_Header_v.Org_Location_ID AS Org_Location_ID,
M_InOut_Header_v.ContactName,
M_InOut_Header_v.Title,
M_InOut_Header_v.EMail,
M_InOut_Header_v.Phone,
M_InOut_Header_v.BPGreeting,
M_InOut_Header_v.Name2,
M_InOut_Header_v.Name,
B.City||'.' AS BAddress,
M_InOut_Header_v.C_Location_ID AS C_Location_ID,
M_InOut_Header_v.BPContactGreeting,
--M_InOut_Header_v.BPGreeting,
--M_InOut_Header_v.Name,
--M_InOut_Header_v.Name2,
M_InOut_Header_v.Address1,
M_InOut_Header_v.Address2,
M_InOut_Header_v.Address3,
M_InOut_Header_v.Address4,
M_InOut_Header_v.City,
M_InOut_Header_v.POSTAL1,
M_InOut_Header_v.CountryName,
--M_InOut_Header_v.BPContactGreeting,
--M_InOut_Header_v.Name,
M_InOut_Header_v.OrderRemarks,
(SELECT NVL(C_Order.DocumentNo,'')||'
- '||NVL(TRIM(TO_CHAR(C_Order.DateOrdered,'DD/MM/YYYY')),'')
FROM C_Order
WHERE M_InOut_Header_v.C_Order_ID=C_Order.C_Order_ID
) AS CC_Order_ID,
M_InOut_Header_v.C_Order_ID AS C_Order_ID,
M_InOut_Header_v.OrderType,
M_InOut_Header_v.ReferenceNo,
M_InOut_Header_v.POReference,
(SELECT NVL(M_Warehouse.Name,'')
FROM M_Warehouse
WHERE M_InOut_Header_v.M_Warehouse_ID=M_Warehouse.M_Warehouse_ID
) AS DM_Warehouse_ID,
M_InOut_Header_v.M_Warehouse_ID AS M_Warehouse_ID,
(SELECT NVL(M_Shipper.Name,'')
FROM M_Shipper
WHERE M_InOut_Header_v.M_Shipper_ID=M_Shipper.M_Shipper_ID
) AS EM_Shipper_ID,
M_InOut_Header_v.M_Shipper_ID AS M_Shipper_ID,
M_InOut_Header_v.Vehicle_No_BizInt,
M_InOut_Header_v.TrackingNo,
M_InOut_Header_v.Permit_No_BizInt,
M_InOut_Header_v.LR_Number_BizInt,
M_InOut_Header_v.FREIGHTCOSTRULE2,
M_InOut_Header_v.FreightAmt,
M_InOut_Header_v.POREMARKS,
M_InOut_Header_v.NoPackages,
M_InOut_Header_v.Gross_Weight_BizInt,
M_InOut_Header_v.UOMSymbol,
M_InOut_Header_v.SalesRepPhone,
M_InOut_Header_v.SalesRepEmail,
M_InOut_Header_v.DocumentType,
InOut_Header_v.DocumentNo,
M_InOut_Header_v.MovementDate,
M_InOut_Header_v.Description,
(SELECT NVL(M_InOut.DocumentNo,'')||'
- '||NVL(TRIM(TO_CHAR(M_InOut.MovementDate,'DD/MM/YYYY')),'')
FROM M_InOut
WHERE M_InOut_Header_v.M_InOut_ID=M_InOut.M_InOut_ID
) AS FM_InOut_ID,
M_InOut_Header_v.M_InOut_ID AS M_InOut_ID,
M_InOut_Header_v.DocumentTypeNote,
M_InOut_Header_v.REMARKS1,
M_InOut_Header_v.REMARKS2,
M_InOut_Header_v.REMARKS3,
M_InOut_Header_v.REMARKS4
FROM M_InOut_Header_v
LEFT OUTER JOIN C_Location A
ON (M_InOut_Header_v.Org_Location_ID=A.C_Location_ID)
LEFT OUTER JOIN C_Location B
ON (M_InOut_Header_v.C_Location_ID=B.C_Location_ID)
WHERE (M_InOut_Header_v.M_InOut_ID=1002241)
AND M_InOut_Header_v.AD_Client_ID IN (1000008,0)
AND M_InOut_Header_v.AD_Org_ID IN (1000099,1000098,0,1000100,1000096,1000097)
AND (A.C_Location_ID IS NULL
OR A.C_Location_ID NOT IN (
SELECT PA.Record_ID FROM AD_Private_Access AS PA
WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144
AND PA.IsActive = 'Y'
))
AND ( B.C_Location_ID IS NULL
OR B.C_Location_ID NOT IN (
SELECT ADP.Record_ID FROM AD_Private_Access AS ADP
WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144
AND ADP.IsActive = 'Y'
))
ORDER BY M_InOut_Header_v.DocumentNo;
This gives me:
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 80 Column: 26
But I didn't find any mistake in that line. I think it is syntactically correct.
The line number is slightly misleading, but it's pointing to the start of the problem. The issue is with these two subqueries:
SELECT PA.Record_ID FROM AD_Private_Access AS PA
WHERE PA.AD_Table_ID = 162 AND PA.AD_User_ID <> 1013144
AND PA.IsActive = 'Y'
and:
SELECT ADP.Record_ID FROM AD_Private_Access AS ADP
WHERE ADP.AD_Table_ID = 162 AND ADP.AD_User_ID <> 1013144
AND ADP.IsActive = 'Y'
You cannot use AS to mark an alias for a table name, only (optionally) for a column name or expression. There isn't actually a missing parenthesis. It's hard to know exactly what the parser is thinking, but in this case it looks like it's trying to interpret the AS PA as a column alias for that subquery, and that implies that the subquery should have ended by now, and so there should have been a close parenthesis already. (Another option might have been to try to treat AS as the table alias, but then it would have had to try to decide what PA meant; plus AS is a keyword so it wouldn't be valid as an alias name anyway).
Just remove the AS keyword from both of those and it'll work (or move on to another error).
SELECT PA.Record_ID FROM AD_Private_Access PA
...
and:
SELECT ADP.Record_ID FROM AD_Private_Access ADP
...