I have the following SQL table username Month 292 10 123 12 123 1 123 2 123 4 345 6 345 7 I want to query it, to get each username’s login streak in Count of sequential Month. meaning the end result I am looking for looks like this : username Streak 292 1 123 3 345 2 How can
Tag: database
Trouble dealing with max() function in SQL Server
The whole code is part of a stored procedure. I have two pieces of code: This one works fine. On the line this particular code is producing the output: and the other one: This is not working correctly. I get an error: Subquery returned more than 1 value on this line Independently it produces this output: Column and table names
MySQL ignore NULL Value while using LAG() function
I want to calculate the MonthByMonth difference of payments happening throughout the year. For example, if I had 100 payments in February & 120 in the month of March, the difference would be 20. I have already made a query that uses LAG(), but the only problem I’m facing is that the query is showing NULL Value. Since there are
Find rows that have the same value and select the newer one
I got a table, that looks like this: serialNr sensorNr ModifyDate 1234 12EE56423 2022-04-06 4567 12EE56423 2018-06-12 6789 AD3FF0C44 2018-03-08 9101 AD3FF0C44 2019-06-07 From rows with the same sensorNr, I only want to select those with newer ModifyDate, so the result should look like this: serialNr sensorNr ModifyDate 1234 12EE56423 2022-04-06 9101 AD3FF0C44 2019-06-07 How can I achieve that? Answer
Output number of non-consecutive failures from historical data in Bigquery
this is related to my previous scenario. I have a dataset like this: Aside from outputting the timestamp in which a user first committed a failure, and consecutively commits a failure status every day, leading up to today (2022-04-29), I also want to output the non-consecutive block of days in which Karl or Andrea commits a failure. In this case,
Oracle SQL find columns with different values
I have two tables A and B both with some millions rows and around one hundred columns. I want to find which columns have different observations without the need of listing the names of all the columns. For example, suppose column ID is the primary key in both tables. And that table A is while table B is The result
Search in the database
This Messages form display table with these informations (ID,FROM,TO,TITLE,MESSAGE). I am trying to search for all the messages send to a certain user . user will enter his name in the Search_textBox then it will filter the table to keep only messages to this user. I get this error : Answer this is Correct
How to get the 2nd record for a customer purchase?
I’m working on a customers database and I want to get all data for their second purchase (for all of our customer weather they have 2 or more purchases). For example: I want to display the second order which is: I’m facing some difficulties in finding the right logic, any idea how I can achieve my end goal? 🙂 *Note:
MySQL Filter on many-to-many on recipes – ingredients tables
In my application, I have 3 tables: recipes ingredients recipes_ingredients I need to find all those recipes that contain a list of ingredients_id and that I have in my food storage and containing NO OTHERS ids outside the list I provided (so not in my food storage). Example: i provide oil (id=111) bread=(id=222) result recipes: OK oil+bread OK bread OK
can’t set a foreign key on oracle sql
Here is my code: and it gave me this error: What is wrong with parenthesis in my code? this only happens when i set foreign key. Note: i am using SQL cmd from Oracle Database 11g Express Edition. I’ve tried making theses tables on MySQL and it worked fine. Answer No “FOREIGN KEY” keyword is used for inline constraints. So,