I did 3 different queries using with clause: WITH non_max_ratings as ( SELECT rating FROM sailors WHERE rating<(SELECT MAX(rating) FROM sailors) ) SELECT rating FROM non_max_ratings nmr …
subquery fetching 2 columns
In Access database file, I have: T1 T2 I need the resulting table to have 1 row (from T1) with the most relevant U_Price, in the example 21.1$ with the highest FromDate smaller than the TransactionDate The question has been properly answered here but now I need to fetch Type also Answer Consider:
Calculating Datediff from nested json sql query
I am trying to use datediff() to find the age of a person in a postgres db (from their date of birth(. I know I can run datediff() like this SELECT DATEDIFF(current_date, ‘2021-01-24’); The query i …
Calculate time in List without using a loop
Is there a way to calculate the data on my List without using loop? My concern right now is it takes longer to process the 5000 ids of employee with different LogIn and LogOut using for loop in a week. What i’ve done is the data is uploaded from csv to the database. Once all the data is uploaded i
SQL injection curiosity
Student here, just learned that in order to avoid SQL injections it’s better to use the prepare/execute duo: instead of the using: the question is: In what situations does anybody use query instead, since we have a pretty quick way to secure ourselves from SQL injections, does anybody use the query meth…
Transform JSON rows into PostgreSQL Table
I have a table in my database that returns me some columns. One of them is a list of JSONs that are, in fact, other tables, but in JSON format. The image belows show an example. I want to transform each row of that column “data” into separate tables, because I need specific information inside each…
Setting rules for max() with strings
Each record in my table has a random selection of these strings, so it looks like I want to get the highest value of “fruit” for each record, except I want it to be sorted lower if it contains the string guava. This is the output that I’d like and I’m using Snowflake SQL output: Curren…
mysql calculate using combination of sum and product formula
I have a table in mysql with data looking like this example. I want to calculate a columnn colc using the formula: C1 = A1*B1; C2 = (C1+A2)*B2; C3 = (C2+A3)*B3; C4 = (C3+A4)*B4; … ColA ColB ColC 1 5 5 2 6 42 3 7 315 4 8 2552 Answer You can use a recursive CTE: See demo here.
Sum with two column is SQL Oracle
I have two columns in a SQL table and I need a third column with the sum of the other two. It’s possible to add a calculated column? Answer Yes it is possible. I did this in the following query, of course, if the columns are numeric If you want to combine two columns, use the following query
Impala Last_Value() Not giving result as expected
I have a Table in Impala in which I have time information as Unix-Time (with a frequency of 1 mSec) and information about three variables, like given below: ts Val1 Val2 Val3 …