I currently have many databases on a server. I want to run a query on only databases that end in “AccountsLive”. Not all of them end with this, so I kind of want to do a wildcard %AccountsLive query and not using a WHERE NOT name IN(‘master’, ‘tempdb’, ‘model’, …
mySQL – create table error 1064(42000): syntax error
I’m trying to create the table below but I get an error. I double checked and the data types are valid, and a table with this name doesn’t currently exist in the database. I even closed and re-opened my terminal in case this was a glitch. But still no luck. Any idea what’s wrong here? Error …
How to calculate the difference between current row and the last row of last month?
I have a postgres table net_value as above, one row one day. How can I calculate the difference between current row and the last row of last month? Look like the output as below: Thanks! Answer Hmmm . . . Here is a method with a join: I also think an approach using window functions and a window frame should
One-to-One relationship in database, foreign key should be in tableA or tableB?
Example scenario: 1 employee will only have 1 address and 1 address will only own by that 1 employee. Below are 2 options, which are correct or neither both? More of my confusion is should I place Employee primary key into Address table or place Address primary key into Employee table? I’m using Postgre…
How do select only swipe-in users from the table which has all swipe records
I have a SQL Server table task_swipe_rec which has only 6 columns. I want to know how many people swipe in right now for the assigned task and the list of minutes they spent on those tasks till now. I am expecting to get the list of tasks that are not swiped out (not completed) and number of minutes spent
How to Select ID’s in SQL (Databricks) in which at least 2 items from a list are present
I’m working with patient-level data in Azure Databricks and I’m trying to build out a cohort of patients that have at least 2 diagnoses from a list of specific diagnosis codes. This is essentially what the table looks like: The list of ICD_CD codes of interest is something like [2500, 3850, 8888].…
Select Duplicate SKU’s and put corresponding prices into new adjacent columns
I have the following sql table – with duplicate SKU’s – each with differing prices which represent bulk buy discounts: SKU Price SKU1 $10.00 SKU2 $12.00 SKU2 $9.00 SKU1 $10.50 SKU2 $11.20 How can I use a SQL select statement to get the following output in the table below? Unique SKU’s …
ORA-00907: missing right parenthesis, and nothing is working
I’ve been sitting and looking at this code for a few hours and I don’t understand where I went wrong, why it doesn’t work. ORA-00907: missing right parenthesis I saw that this is a topic that is discussed alot but for some reason none of the examples I have seen has helped me. I’m pret…
List No of minutes worked by an employee using self join
I have a SQL Server table emp_swipe_rec which has only 6 columns. I want to know how much time (in minutes) both employees A and B worked for today (last 24 hours). Employee A already swiped out for the day. Employee B is still working. We don’t store two different columns for a swipe in/swipe out. We u…
Firebird how to use IIF in ORDER BY with a subquery’s column
The following query doesn’t work, because Firebird (2.1) won’t recognize the subquery’s column. How can I rewrite it to work? Answer Use a subquery: I would also recommend using COALESCE() in the ORDER BY: