Skip to content

Passing parameters for a constraint function

I have the following table that joins driver and truck tables in order to assign trucks to drivers. I need to constraint entries that belong to the same driver on the same day, and DO NOT include the same truck code. It was suggested to create a boolean function to pass along dateval, truckval and driverval, …

How to get data for missing weeks in Summarised data

I have two tables stores_data and financial_week as shown below. Stores data is a summarised data across multiple attributes. My task is to generate data for all the weeks present in the second table, if data is missing, the quantity should be listed as 0. Expected Result set is this – I have done cross…

Oracle trigger multiple conditions in when clause

I’m trying to create a trigger that updates a column in a table when other columns are updated. but getting the following error while saving the trigger ORA-25000: invalid use of bind variable in trigger WHEN clause My trigger is as follows, I’m not sure what is wrong with the code. Answer Althoug…

Hive Explode the Array of Struct key: value:

This is the below Hive Table And this is the data in the above table- Is there any way I can get the below output using HiveQL? I tried use explode() but I get result like that: Answer Use laterral view [outer] inline to get struct elements already etracted and use conditional aggregation to get values corres…

Weird behavior of MySQL Server when ordering by 2 conditions

Say a database table my_table has the following structure: and some of the rows in the database have total_votes == 0. I want to get the rows ordered like this, except I also want to include the rows that have total_votes == 0. I tried using the following query, and it worked like a charm: My question is why …

Iterate through query

I’m trying to iterate through simple query This is what I managed to create But I get: Answer You don’t need a while loop for this. You can do this in a single query. One method is: Trying to use a while look is troublesome. Such programming constructs would be in programming blocks. They are desi…