Hive words starting with a vowel - hive

I have a table tbl_2016 with columns col1 and col2. I want to obtain the sum of col1 where col2 starts with a vowel.
I have tried the following code but I am afraid that Hive understands it as starting with “AEIOU” and not “A” or “E” or “I” or “O” or “U”:
select SUM(col1) as Total_col1 from tbl_2016 WHERE col2 LIKE "[AEIOU]%";

Try using RLIKE to match regex:
select SUM(col1) as Total_col1 from tbl_2016 WHERE col2 RLIKE '^[AEIOU]';

Related

How to delete defined value from the begining of character in Oracle SQL?

I have table in Oracle SQL like below:
col1
--------
ABC|1234
ABC|55674
ABC|11
So I have in col1:
always "ABC|" at the begining of each value
different length of values after "ABC|"
I need result like below, so I need to delete "ABC|" from begining of each value
col1
---------------
1234
55674
11
How can I do that in Oracle SQL ?
A simple substring operation might be easiest here:
SELECT col1, SUBSTR(col1, 5) AS col1_out
FROM yourTable;
You could also do a replacement:
SELECT col1, REPLACE(col1, 'ABC|', '') AS col1_out
FROM yourTable;

DB2 SQL Select All With Columns As

I am working with some SQL queries on DB2. Is it possible to select all the columns in a table and also specify certain conditions using the "as" keyword within that select statement? For example, is this query possible:
select
*,
col1 + col2 as sum1,
col3 - col4 as dif1
from
table;
Whenever I attempt this, I am getting the SQL0104 error and it is saying "Token , was not valid. Valid tokens: FROM INTO".
Thank you for your help.
EDIT:
This query is running inside an SQLRPGLE program on an AS400.
Put your table alias in front of the *. So:
select
t.*,
col1 + col2 as sum1,
col3 - col4 as dif1
from
table t;

Insert Statement for List

I'm not too sure how to describe my SQL Insert statement so I will describe the expected result.
I'm building a data extract list and have a table that I've put all my data into. It's called _MATTER_LIST
What I am trying to Achieve is to have the Client_Number + Col1 combination repeat after every unique COL1+COL2+COL3 combination but not duplicate when there is already a CLIENT_NUMBER+COL1. So the end result would be:
thanks in advance for any tips.
Simple ORDER BY should work for you if i understand. Try this :
select Client_Number, Col1, Col2, Col3 from _MATTER_LIST
order by Client_Number, Col1
I've managed to fix my own issue. I added a unique key for the col1 + col2 + col3 , then make col2 repeat over each combination for example.
The result is: select * from _MATTER_LIST order by COL4, COL5

Reject a row based on 2 column values

Below is the output of a simple join query. All the 3 columns are from different tables.
Col1 Col2 Col3
Manual Y-Yes Include
MC Y-Yes Include
Manual Y-Yes Exclude
Manual Y-Yes Exclude
I need to get the rows with 'Include' only if there is no 'Exclude' for the same Col1 value.
If there is no 'Exclude' for the Col1 value, then its fine to display 'Include'.
So the query should not display the first row according to the requirement since the Col1 value 'Manual' has 'Exclude'.
Your sql query should look a lot like what your question would be in English:
You want all the rows where there is no row for the same col1 value that has 'Exclude' in the col3 value, right?
I cannot give exact sql since you do not provide table or column names, but if all three columns were in the same table, it would look like this:
Select * from mytable
where not exists
(select * from mytable
where col1 = t.col1
and col3 = 'Exclude')

query to find specific word in a cloumn using oracle database

can anyone help me in the below query.
I wanted to find the records which have "word1" in col1 and we can write the below query for that but do we have any other option/operator that we can find the exact word in the col1 without prefix and postfix.
Select col1, col2 from table1
where col1 like '%word1%'
or col1 like '%word1'
or col1 like 'word1%'
or col1 = 'word1';
Note: I know that we can use contains operator but it uses the index which i don't want.
Please let me know is there any other way to represent above quer in a simple manner.
you want something like like .. but why?
If it is for a learning, you can use INSTR()
Select col1, col2 from table1
where INSTR(col1,'word1') > 0
Otherwise best approach is
Select col1, col2 from table1
where col1 like '%word%'