I have a dataset looks like this and i need a query which returns 2 random values from where country in (‘a’, ‘c’): Answer This should work: Replace rand() with random() if you’re using Postgres or newid() in SQL Server.
If there are several Positions, then find only the main one, otherwise take another
Need to filter the records so that the employee mostly has only the position with the employment type 0. I can’t just do where TypeEmployment = 0, because it will cut off the employee with private face id 3406 But I would like to see him, because he does not have a position with type 0 However, the employee with
Why is this Index Scan so slow?
From what I can see, the index is not entirely loaded up in memory, and that’s what causing it to be slow? Am I correct? obs: I changed the “Output” section a little bit for privacy concerns Answer The index scan is fast (1.774 milliseconds on average). The execution is so slow because the index scan is executed 46257 times.
Get distinct values within time chunks
I have a table with different species and their occurences (timestamp) from field survey: Now I want to count them, not in total but in chunks of 10 minutes each, where only the first occurence is counted. That means between 12:31 and 12:40 there are species A,B,C. Between 12:41 and 12:50 there are species B,C. For a single 10 minute
can indexing SQL tables improve the performance of a tableau dashboard?
I have a very high level question. could indexes on a sql server table improve the loading performance of a tableau dashboard? if so – is there any best practice / guideline we could follow? thanks a lot Answer Yes, it will speed up Tableau. Just like the indexes speed up any query (if applied properly), Tableau is the same
Mongo Group By query
I have data stored in a Mongo collection that is structured like this: I wish to construct a query that would let me sum up each count in each entry and group by requestingSupplier. For example, I would like to answer the question, for the month of January ’22, what was the sum of each entity and get a response
How can i add days to a Hive timestamp without loosing hours, minutes and seconds
I am using Hive 2.6.5 and when i want to add days to my timestamp, it doesn’t keep the hours, minutes and seconds. Exemple in addition to that it returns a wrong result as : I would like it to return the value 2021-01-17 09:34:21 Thank you Answer date_add truncates Unnecessary unix_timestamp+from_unixtime conversion Convert to timestamp, add interval: Result: Timestamp
SeedTable.SomeColumn +1 in a recursive CTE not working as expected
I’m trying this query in Redshift: but I keep getting this error: (500310) Invalid operation: column “level” does not exist in child, parent; 1 statement failed. What am I doing wrong? According to the documentation I found here, Redshift accepts recursive and this is the way to go about it: https://docs.aws.amazon.com/redshift/latest/dg/r_WITH_clause.html#r_WITH_clause-recursive-cte Answer I believe that for recursive cte, the cte
SQL check if Int is null select NVarchar
I want to check if an INT is null, and if so select a different name for the value. But I keep getting a Conversion failed when converting the varchar value ‘NAME’ to data type int I want something like.. Simply, if null select the second name, otherwise if it has a value, select the first Answer Use a case
How to check TIMESTAMP format in SQL?
What’s the best way to check if the VARIANT TYPE with JSONs with value similar to TIMESTAMP_NTZ has correct format? For example, this is the correct format that I would like to have but there are times when it looks different in database, like this I would like to detect records which are in a different format than the reference.