Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

0 votes
1 answers
195 views
Calculate (n) workdays from a given date, using a calendar table
As shown on below image, I have two tables; - **Customer** : with about 4 million records; and 3 columns [Customer] : Customer ID [Date] : Creation date [Num_Days] : Number of working days to calculate the [next_wkday] in the query result. - **Calendar** : with all calendar days; and 3 columns [ref_...
As shown on below image, I have two tables; - **Customer** : with about 4 million records; and 3 columns [Customer] : Customer ID [Date] : Creation date [Num_Days] : Number of working days to calculate the [next_wkday] in the query result. - **Calendar** : with all calendar days; and 3 columns [ref_date] : dates [civil_util] : when (1) -> workday; when (0) -> non working day [year] enter image description here I need to get the **query_result** with the three columns of Customer Table and a calculated date [next_wkday], representing the number of working days [Num_Days] after each customer Creation date, jumping the zeros (*non working days*) in the [civil_util] column. I've created the query below to calculate the [next_wkday] using the Lead() function. But is not a solution because the **offset parameter** must be a constant, and we need to use the [Num_Days] value for each Creation Date: select *, Lead (to_date(ref_date),5) OVER (ORDER BY to_date(ref_date)) AS next_wkday, datediff(Lead (to_date(ref_date),5) OVER (ORDER BY to_date(ref_date)),ref_date) as days_diff from calendar where ref_date >= to_date(now()) and civil_util = 1 limit 1 Basicaly I need to solve two problems: 1 - Must be a query to perform the calculation Because I don't have the profile to create functions in the database. 2 - I need to design a query that achive the ***Query result***, shown in the image, that will able to join both, the Customer table and the calculation query. So, I need to find another solution. And that solution must work in two engines: 1. Impala version : impalad version 2.12.0-cdh5.16.2 2. Oracle 11g I need to reinforce, for performance puposes, that the Customer table has 4 billion records approximatly. Can anyone help please? My best regards
LEOPOLDO (1 rep)
Oct 2, 2023, 10:25 AM • Last activity: Jun 23, 2025, 10:01 PM
0 votes
0 answers
257 views
Get Join Keys dynamically from a table
SQL/Impala I have a scenario where I need to join my input file with a mapping table which has map columns and derived columns. The join keys are dynamic and need to taken from a dynamic metadata table. Metadata table can be modified by user to either update or insert new keys. The join happens in m...
SQL/Impala I have a scenario where I need to join my input file with a mapping table which has map columns and derived columns. The join keys are dynamic and need to taken from a dynamic metadata table. Metadata table can be modified by user to either update or insert new keys. The join happens in multiple passes. Pass1 will have one set of columns as keys , Pass2 will have another set of columns as join keys. Pass2 derived values can overwrite Pass1 derived values. The derived columns are same through out. Example: Keys metadata table enter image description here Mapping Table enter image description here In Input File enter image description here Join keys for Pass1 are A,B,C,D,E. Join will map values 10,20,30,40,50 from Input file to Values 10,20,30,40,50 in mapping table - DerivedValues1,2,3,4 will be derived. Join Keys for Pass2 are A,B,C,D - Join will map values 10,20,30,40 from Input File to values 10,20,30,40 in mapping table - DerivedValues1,2,3,4 will be derived and can overwrite values derived in Pass1 In Pass3 - Column A and Derived Value3 will be join key. Join will map values 15, Jasmine to mapping table - DerivedValues1,2,3,4 will be derived. Any idea how we could do this in SQL or Impala. Basically the platform is built in Big Data and we just need to write SQL like queries to implement this logic Appreciate any help. THanks Nitin
Nitin Shelke (1 rep)
Jun 2, 2021, 11:58 AM
2 votes
1 answers
1498 views
how to insert data into extra columns of target avro table when source table is having less no of columns compared to target using hive or impala?
Suppose I am having a source Avro table having 10 columns and my target Avro table is having 12 columns, while inserting data into the target table I need to add null values to the extra 2 columns. But when I execute the below query it has thrown the exception > AnalysisException: Target table 'targ...
Suppose I am having a source Avro table having 10 columns and my target Avro table is having 12 columns, while inserting data into the target table I need to add null values to the extra 2 columns. But when I execute the below query it has thrown the exception > AnalysisException: Target table 'target_table' has more columns (8) than the SELECT / VALUES clause returns (7) insert overwrite table target_table select * from source_table; How to make advantage of Avro table automatic schema change detection here? **Note:** Suppose if I want to insert only 5 columns to the target and the rest should be default null. So how to achieve this?
user109612 (21 rep)
Nov 3, 2016, 09:53 AM • Last activity: May 25, 2021, 08:59 AM
0 votes
1 answers
35 views
Retrieving orders that only contain certain product IDS
I am trying to retrieve a list of transaction IDS that only contain at least 5 product IDS, the baskets could have many more product IDS but it must contain these 5 also. My table looks something like this: | transaction_id | trans_date | product_id | store_id | The table is all at `product_id` line...
I am trying to retrieve a list of transaction IDS that only contain at least 5 product IDS, the baskets could have many more product IDS but it must contain these 5 also. My table looks something like this: | transaction_id | trans_date | product_id | store_id | The table is all at product_id line level detail, nothing is rolled up. select * from Transactions where trans_date in ('2019-03-07','2019-03-06','2019-03-08','2019-03-09','2019-03-10') and product_id in ('000000000021003503','000000000060280873','000000000060281480','000000000060281642','000000000020059281') This is recovering all the transactions that contain these ids but I need it to be rolled up to a transaction level, so if the transaction_id contained these ids (at least) then its included. Hopefully this makes sense
RustyRyan (89 rep)
Mar 11, 2019, 09:57 AM • Last activity: Mar 11, 2019, 12:54 PM
1 votes
1 answers
6622 views
Splitting a table into two tables randomly with 50-50 percent of records in impala
I have a table having n number of records in impala. I need to find out how can I divide that table into two equal halves with 50 - 50 percent of records in each.
I have a table having n number of records in impala. I need to find out how can I divide that table into two equal halves with 50 - 50 percent of records in each.
user97537 (11 rep)
Jun 10, 2016, 09:09 AM • Last activity: Oct 7, 2017, 09:14 AM
Showing page 1 of 5 total questions