hive equivalent of group concatenation - hive

what is the wrong with this hive query ..trying to do group concatenation
select ID,source_sys, group_concat(Quote||'_'||Quote_size::Integer||'#'||price::Numeric(30,4)
||'_'||quote2_size::Integer||'#'||quote2_price::Numeric(30,4),'|') as quotes from xyz_table
I am getting the following error
Analysis Exception: Syntax error on line 2:undefined: ...Quote||'_'||Quote_size::Integer||'#'||price ... ^Encountered::Expected: ADD,ALTER .....
Syntax error

in group_concat just use comma.. I believe only in oracle they use || for concatenation.
select group_concat(Quote,'_',Quote_size::Int,..) from yourtable
See more examples here https://docs.cloudera.com/documentation/enterprise/5-5-x/topics/impala_group_concat.html

Related

Error with group by in DB2 - SQLSTATE 42803

I've got a SQL script and its failing. This is what it looks like:
SELECT P.SOORT,P.TYPEBETALING, P.MIDDELCODE, P.HOEVEELHEID, P.EENHEID, P.BEDRAG,P.MIDDEL
FROM DAAO01.BETALINGEN as A join
DAAO01.KLANTEN P
on p.KLANT_ID = 1
GROUP BY P.TYPEBETALING
ORDER BY P.TYPEBETALING
When I execute this I get an error:
COLUMN OR EXPRESSION IN THE SELECT LIST IS NOT VALID. SQLCODE=-122, SQLSTATE=42803, DRIVER=4.18.60
What am I doing wrong?
It is quite difficult to tell what you're trying to do without seeing your data.
But the error is saying that you have not specified how you are going to deal with the rest of the fields in your Group by aggregation:
P.SOORT, P.MIDDELCODE, P.HOEVEELHEID, P.EENHEID, P.BEDRAG, P.MIDDEL
If they're numbers, then you could sum them or take the avg etc.
If they're strings, then you either need to group by them or remove them from your selection.

unable to execue the following select statement getting error

when i execute the following select statement i am getting the below error.
I am trying to execute the below statement in Oracle server 9.1.
I believe due to this i am getting this error.
I know we can excute the query for single quotes by '%Blondeau D''Uva%'. But i am looking for query which will pass the special character value as parameter.
Kindluy let me know how to escape single quotes in old oracle server
ERROR :
ORA-00933: SQL Command not properly ended
Error at line : 1 Column : 50
Query:
Select * FROM TABLEA where UI_FNAME like q'[%Michael%]' and UI_LNAME like q'[ %Blondeau D'Uva%]';
On oracle the following should work
Select *
FROM TABLEA
where UI_FNAME like '[%Michael%]'
and UI_LNAME like '[ %Blondeau D''Uva%]';
So no duplicate where
And you have to quote the ' between D und Uva
And probably the q before the ' is wrong ... so I have removed it as well.
Ok tried it out with the q operator:
Select *
FROM employees
where first_name like q'[%Michael%]'
and last_name like q'[ %Blondeau D'Uva%]';
No errors no row ...
Two things about your query:
Two times usage of where where there should be just one.
About the second condition. You have used q'[ %Blondeau D'Uva%]' in like clause. I think that won't give you the result you might be looking for. This has nothing to do with your error, but still, it would not hurt to re-check the query.
Try this, this shouldn't run you into any error :
Select * FROM TABLEA
where UI_FNAME like q'[%Michael%]'
and UI_LNAME like q'[%Blondeau D'Uva%]';
Cheers!
As others have tried to give you an answer, but I think you probably need to keep % outside brackets -
Select *
FROM TABLEA
where UI_FNAME like '%[Michael]%'
and UI_LNAME like '%[ Blondeau D''Uva]%';

ORA-01722: invalid number error

I am running the below mentioned query in my Oracle client and i am getting
ORA-01722: invalid number
error. I know the issue is due to the TAG_VALUE column being of type "varchar2" and i am converting it to number and then using that field in where clause. I have tried using "CAST" function but that is also not helping.
If i run the query neglecting the last where condition with code WHERE (P.TAG_VALUE > '100') then i am getting the result but including the last where clause gives me error.
SELECT DISTINCT
count(P.CREATED_DATETIME)
FROM
(
select OUTPUT_TAG_ID,TO_NUMBER(TAG_VAL,'9999.99') AS
TAG_VALUE,TAG_VAL_TS,CREATED_DATETIME
from OV80STG.PRCSD_DATA_OUTPUT_ARCHIVE
where MODEL_CODE='MDLADV1538'
AND TAG_VAL <> 'U_Transfer_rate'
) P
WHERE
(P.TAG_VALUE > '100')
Any suggestion will be appreciated. Thanks.
Remove the single quotes from around the value in the where, you don't need them when its an integer. query will be like this:
SELECT DISTINCT
COUNT(P.CREATED_DATETIME)
FROM
(
SELECT
OUTPUT_TAG_ID,
TO_NUMBER(TAG_VAL, '9999.99') AS TAG_VALUE,
TAG_VAL_TS,
CREATED_DATETIME
FROM OV80STG.PRCSD_DATA_OUTPUT_ARCHIVE
WHERE MODEL_CODE = 'MDLADV1538'
AND TAG_VAL <> 'U_Transfer_rate'
) P
WHERE(P.TAG_VALUE > 100);
TO_NUMBER function returns a numeric value so, as mentioned in comment, you shouldn't compare it with string value.
I solved the issue by including outer where clause inside the subquery and then I got the required result without any error.

BigQuery Error while trying to query data?

I am trying to run simple query on Google Bigquery. But each time when I run the query SELECT COUNT(totals.visits) FROM 122443995.ga_sessions_20160817 I get following error
Encountered " "FROM" "FROM "" at line 1, column 29. Was expecting: <EOF>
What could be the possible error in the query syntax?
You probably need to escape the table name. With legacy SQL, you would use square brackets, e.g.:
SELECT COUNT(totals.visits) FROM [122443995.ga_sessions_20160817];
With standard SQL, you would use backticks, e.g.:
SELECT COUNT(totals.visits) FROM `122443995.ga_sessions_20160817`;
For me, using parentheses to surround the clause in FROM solved it for me.
So instead of
SELECT totals FROM t1
use
SELECT totals FROM (t1)

DB2 count(*) over(partition by fieldname) giving -104 z/OS version 7

I have slimmed down the query to remove potential complications, in addition I have verified that the fields are correct. DB2 UDB zSeries V7 is my db2 version.
SELECT
STDINSTRCD,
COUNT(*) OVER(PARTITION BY STDINSTRCD),
CAST(STDINSTRDESC AS VARCHAR(1000)) AS INSTR,
C.STDINSTRSEQ,
1
FROM
SYST.SCC004 C
WHERE
C.STDINSTRCD = '098'
I have tried a subquery as well.
select
H2.FRSTSTDINSTRCD,
(select count(*) from SYST.scC004 Ci where '098'=Ci.STDINSTRCD) as cnt,
cast(STDINSTRDESC as varchar(1000)),
C.STDINSTRSEQ,
1
from SYST.scE4A00 H2
LEFT OUTER JOIN SYST.scC004 C
ON C.STDINSTRCD = H2.FRSTSTDINSTRCD
WHERE
H2.CTLENTYID='MCS'
AND H2.VCKVAL='12654'
AND H2.POKVAL='0198617S12 000 000'
The error is receive is om.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: (;, FROM INTO sqlcode sqlstate
-104 Illegal Symbol token.
42601 A character, token, or clause is invalid or missing.
Any advice? I have been unable to determine what syntax error I might me making.
are there any weird special characters in there that might not be printing?
http://www-01.ibm.com/support/docview.wss?uid=swg1IY43009
basically sounds like a weird cr/lf or special char? Any copy pasting from *nix to windows ?
Also, I'm not sure why you need partition by anyway? would a group by not accomplish your goal. (looks like your just counting number of rows that met your criteria)...
something like this for your first query?
SELECT
STDINSTRCD,
count(1) ,
CAST(STDINSTRDESC AS VARCHAR(1000)) AS INSTR,
C.STDINSTRSEQ,
1
FROM SYST.SCC004 C
WHERE C.STDINSTRCD = '098'
group by
STDINSTRCD,
CAST(STDINSTRDESC AS VARCHAR(1000)) AS INSTR,
C.STDINSTRSEQ,
1
Db2 Version 7 for z/OS does not support OLAP functions, or row_number(). You need to rewrite your query to avoid using such functions. They arrived in later Db2 versions. See also other people's tips on alternatives via this link.