I’m trying to figure this out, but it’s driving me insane! How do I calculate in SQL the number of days that are in a specific year between two dates? For example: we have the range date [12/30/2016-01/05/2017]. If I need to find how many days are in 2017 between this range of dates, it would be 5…
SQL WHERE condition when one does not return true, then try other
I have to query a table based on two fields such that if first field matches then don’t check the second but if first field does not match then check if second field matches for a value something like: But if first condition succeeds, it must not check for second condition Example: Suppose the following…
SQL CASE WHEN won’t meet condition
This is a solution to one of the leetcode problem. It is asking me to output the second highest salary from the table and if there are no second highest salary then the output should be null. The above is my solution. I used case and when syntax but the problem is that even when the table only has 1
Not able to create a matrix in PL/SQL using nested tables
I was trying to create a matrix in PL/SQL using nested tables as such: firstly, I create a table type that is able to store varchars (that in my case is name lista_principala) secondly, using the previously declare table type lista_principala I try to create a table type that contains items of type lista_prin…
Return all values from objects using OPENJSON()
Here is my problem: My JSON may vary based on API response and there is no guarantee that “shortTitle”, for example, can be present in my JSON next time when there is a post request. I have to figure how to “loop” (if that’s the correct term) through JSON to get all fieldID and c…
How to vertically flip the column values top to down in SQL
How to vertically flip the column values from top to bottom in SQL which are not in any specific order(neither asc nor desc)? Example: Table named ‘Country’ has a single column c1 with values Now I want to display the Result-set as below: If anyone can kindly suggest? Answer It’s not possibl…
Duplicated inner join results
With postgres I’m trying to get a single user and all their posts, but when I inner join the Users and Posts tables I receive this: QUERY: I’m also trying to do the same thing but as a json QUERY: I know why but I don’t know how to avoid it, can someone help me to get something like this:
PLS-00225 subprogram or cursor ” reference is out of scope when try to read column names
I’m trying to return the column names and the value as a pair key/value like this: column_name | column_value dep_id | 1 dep_name | ‘Test’ dep_create_date | ’08-25-2021′ When I execute this block, I got the following error message: Error report – ORA-06550: line 6, column 2…
How to select a query from mysql database based on a certain condition
I want to answer the following question using the below Mysql tables. How many days were the user active on avg. (had an action) in the last week? I want to Display user Avg by day, where ((user action is not 0)/unique day) in the last 7 days. 0 means the user is not active and 1 means active. I
MySql query to return a random row returns unexpected number of rows
I am trying to get a random word from a long list of words in a MySql table: word_list [id*|wword]. My query looks at the moment like this: SELECT * FROM word_list w where id = (SELECT FLOOR(1 + RAND()*(10-1))) I thought the above query would return one and only one random row with Id between 1 and 9. To