Skip to content
Advertisement

Tag: hql

Getting sql data based on row value

I have a table like so: I’m trying to get the last date when the account was active, not counting today. If the id is not present on today’s date, it is not included in the final table. So for the case of id 1, that would be 2022-04-02, and for id 2, it would be 2022-04-01 I can do

Replace values based on JOIN

Let’s say I have two data sets A and B After left join I should get FALSE value for Y in table A as it doesn’t have it in table B Answer Using your approach, if you intend to get a value of FALSE if the value doesn’t exist you can check for NULL in the name. The example below

Select using WHERE if any exist, else don’t use WHERE

I want to select from a table where column = ‘n’. If the result has 0 rows, I want to remove that conditional. Some pseudo-sql might be: I will only be using the first row in either result, so it would also be acceptable to somehow sort the result such that rows where COL_B = ‘mystring’ appear at the top.

Case condition in hql

What I’m trying to achieve with this query is: always do the “mother” conditional, but if there isn’t mother, then do the “dad” conditional, is this posible? Answer This query: will try to join first by matching the column idMother to :idMother. If this is not possible then a match of idFather to :idFather will be used, if it exists.

Percent change with grouping variables

I have four grouping variables Month, State,County, City. In addition I have the metric column sales which can be null I would like to calculate the percent change of sales per month for each City. My solution would have the same grouping but with the sales column replaced by percent change for each month in calendar year 2019. Any help

[21000][1242] Subquery returns more than 1 row

My Query: Here I get the error – [21000][1242] Subquery returns more than 1 row By the method of exceptions, I determined that the error in this query string: How to make the correct request so that there is no this error? Thank! Answer Two common ways are aggregation and limiting: However, those are really just hacks to get around

How to compare timestamp in HIBERNATE query?

I have one value of timestamp that I retrieve from the database and then compare it with the current timestamp. I actually want to retrieve data of people who have been logged in for the last two hours. Unfortunately, I am facing this error. please help me, guys. I shall be thankful to you. I have stuck in this code.

How to take union and write into the same table?

I have a table A with columns (x, y, z) and I have another table B with columns (x, y, z), basically the same schema. I want to add those rows from B into A, which do not already exist in A, basically after the operation the union of A and B exist in table A. How do I do

Advertisement