I am new to HiveQL and is IN and NOT IN supported in it? Especially when using Qubole?
Here is my query:
SELECT DISTINCT vId FROM table1
WHERE d.columnOne = "123"
AND NOT d.columnTwo
AND timestamp between 1523550000000 AND 1523930000000
AND NOT h.columnThree regexp "000.000.000.00|111.111.111.11|222.22.222.22"
AND vId in (select vId from table2 where colOne regexp "000|111|222")
my error is
"Unsupported language features in query: "
Related
I have a huge_query_that_runs_fine_alone that starts with select.
I want to insert that query result into existing table, but usual SQL statements no work.
I tried: insert into test_ds.test_tbl (field1, …, fieldN) values (huge_query_that_runs_fine_alone), but query editor says me that select keyword in unexpected place;
And this: select * into test_ds.test_tbl from (huge_query_that_runs_fine_alone), but query editor says me this Syntax error: Unexpected keyword INTO at [1:10];
What to do?
P.S. Full query...
insert into test_bq_dataset.test_tbl (Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo, AmountPromo, SumPromo, AmountNoPromo, SumNoPromo) values (select promos.Naimenovanie_SKU, promos.Naimenovanie_TT, promos.MonthNo, promos.YearNo, AmountPromo, SumPromo, AmountNoPromo, SumNoPromo from
(select Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo, sum(Prodazhi_Litry) as AmountPromo, sum(Prodazhi_Summa_s_NDS) as SumPromo from IACloud0539_Calc.Data2_PROMO where Promo = false group by Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo) promos
left join
(select Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo, sum(Prodazhi_Litry) as AmountNoPromo, sum(Prodazhi_Summa_s_NDS) as SumNoPromo from IACloud0539_Calc.Data2_PROMO where Promo = true group by Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo) nopromos
on
promos.Naimenovanie_SKU = nopromos.Naimenovanie_SKU
and
promos.Naimenovanie_TT = nopromos.Naimenovanie_TT
and
promos.MonthNo = nopromos.MonthNo
and
promos.YearNo = nopromos.YearNo);
Syntax error: Unexpected keyword SELECT at [1:149]
You could just place a SELECT query below the INSERT clause and it'll work just fine
ex:
CREATE TABLE temp.mytest5 (col1 STRING, col2 STRING);
And the insertion:
INSERT INTO temp.mytest5 (col1, col2)
SELECT 'record1', 'record2'
Id like to find records with (.XX) extension at the end which don't have corresponding records without an extension (.XX) at the end. Id like to use the "exists" or "not exists" solution if possible as I'm puzzled why mine gives no output.
input
col_a
value1.XX
value1
value2.XX
value3
** expected output**
col_a
value2.XX
code
SELECT *
FROM table1 as a
where
right (table1.[col_a],3) = ".XX"
and exists(
select 1 from table1 b where Left(a.[col_a], Len(a.[col_a]) - 3) = b.[col_a]
)
Hmmm. You
select t1.*
from table1 t1
where t1.col_a like '%.XX' and
not exists (select 1
from table1 tt1
where t1.col_a = tt1.col_a || '.XX'
);
Note: You have not specified your database so this uses the ISO/ANSI standard || for string concatenation. You can check your RDBMs's documentation for the correct concatenation technique.
I need something to build a string in an sql equal statement, composed by two part, the first one choosed by me and the second one dynamically generated by a query
select * from table
where param1= 'test' + (select distinct param2 from table2 where ...)
the second select always return only one record of course.
So the where clause should be where param1='test'+param2
I tried concat function but it doesn't seem the correct way; any suggestion?
Oracle uses the ANSI standard || operator for string concatenation. So, use this:
SELECT *
FROM yourTable
WHERE param1 = 'test' || (SELECT DISTINCT param2 FROM table2 WHERE ...);
The CONCAT function should also work here:
SELECT *
FROM yourTable
WHERE param1 = CONCAT('test', (SELECT DISTINCT param2 FROM table2 WHERE ...));
select * from table
where param1= 'test' || (select distinct param2 from table2 where ...)
I'm trying to do an update using data from another table. I've tried this answer (the second part), but it is not working for me. I'm receiving a generic error message of syntax error.
I've also tried this solution and received a syntax error message too.
If I try to update just one column, it works:
UPDATE dogs
SET name =
(
SELECT 'Buddy'
FROM systables
WHERE tabid = 1
);
But I need to update multiples columns. Unfortunately, this is not working:
UPDATE dogs
SET (name, breed) =
(
SELECT 'Buddy', 'pug'
FROM systables
WHERE tabid = 1
);
Informix version is 12.10.FC8
You are missing 1 more set of parentheses around the subquery.
From the Informix manual:
The subquery must be enclosed between parentheses. These parentheses
are nested within the parentheses that immediately follow the equal (
= ) sign. If the expression list includes multiple subqueries, each subquery must be enclosed between parentheses, with a comma ( , )
separating successive subqueries:
UPDATE ... SET ... = ((subqueryA),(subqueryB), ... (subqueryN))
The following examples show the use of subqueries in the SET clause:
UPDATE items
SET (stock_num, manu_code, quantity) =
(
(
SELECT stock_num, manu_code
FROM stock
WHERE description = 'baseball'
),
2
)
WHERE item_num = 1 AND order_num = 1001;
UPDATE table1
SET (col1, col2, col3) =
(
(
SELECT MIN (ship_charge), MAX (ship_charge)
FROM orders
),
'07/01/2007'
)
WHERE col4 = 1001;
So in order for your update to be accepted by Informix it has to be:
UPDATE dogs
SET (name, breed) =
(
(
SELECT 'Buddy', 'pug'
FROM systables
WHERE tabid = 1
)
);
I am trying to Count the distinct Number of UserID's in a table for each Weekday (e.g. 545 UserID's on Weekday 1 = Monday, 120 UserID's on Weekday 2 = Tuesday etc.). I am doing this in Access Visual Basic, but the syntax should be universal to SQL. Here is my VB Code:
sSQL = " SELECT Weekday(" & tablename & ".[DATE]) AS WEEKDAY, Count(DISTINCT " & tablename & ".[UserID]) AS User_COUNT"
sSQL = sSQL & " FROM " & tablename
sSQL = sSQL & " GROUP BY Weekday(" & tablename & ".[DATE])"
qdf.SQL = sSQL
The plain SQL Syntax should look like this (edited based on comments & test):
SELECT Weekday(tbl.[Date]) AS WEEKDAY, Count(DISTINCT tbl.[UserID]) AS User_COUNT
FROM tbl
GROUP BY Weekday(tbl.[Date])
..whereas [Date] is a field in tbl formatted as Datetime and [UserID] is a field formatted as Long (with duplicates).
When I try to run the command it tells me "Missing Operator in Query-Syntax.."
Is this a problem of my VB Code or is the SQL Syntax wrong?
MS Access database engine does not support COUNT(DISTINCT ...).
To workaroud it, please see this thread: SQL : how can i count distinct record in MS ACCESS where author suggests to solve issue by using subquery:
SELECT
user_id
, COUNT(*) AS count_distinct_clients
FROM
( SELECT DISTINCT
user_id,
client_id
FROM tbl_sActivity
) AS tmp
GROUP BY
user_id ;
Change the query code to your needs.
[EDIT]
SELECT
wday, COUNT(UserId) AS count_distinct_users
FROM
( SELECT DISTINCT WEEKDAY([Date]) AS wday, UserId
FROM tblName
) AS tmp
GROUP BY
wday;