How can I combine these three queries into one? SELECT COUNT(*) FROM Users WHERE (SELECT COUNT(*) FROM Posts WHERE Posts.OwnerUserId = Users.Id) < 10; SELECT COUNT(*) FROM Users WHERE (SELECT …
Oracle SQL if statement?
how would it be possible to check if a certain value in salesman_id is null, and if it is, assign it to something else (in this case, 0)? here’s what i’ve wrote up so far: SELECT O.SALESMAN_ID, SUM(OI….
SQL Server Management Studio : execution timeout expired
I keep on getting a timeout in my Microsoft SQL Server Management Studio. I’m not running any code. All I am doing is trying to look at the tables within a database in the Object Explorer. I always …
add interval to timestamp with milis from jsonb
In DB, I have an array of objects [{“effectiveTo”:”1603939934019″,”effectiveFrom”:1603896734146}] I need to check if effectiveFrom is bigger than now – 7 days or …
STUFF function truncated result
I am trying to generate dynamic sql by querying a table and using the STUFF function and returning the results into a variable (DECLARE @dynamic_query NVARCHAR(max)). My problem is that the results returned by the STUFF function are truncated/incomplete. The content of @dynamic_query will be cut short. I can&…
Can’t enable a foreign key in ORACLE SQL
So I have a disabled foreign key (Manager_ID in the table Employees) and I wanted to enable it, but I get this error: ORA-02298: cannot validate (my_username.EMP_MANAGER_FK) – parent keys not found And this is the code: Here’s how the table was created: Answer There are values in the column that a…
How to define minimum and maximum value as range for a postgresql field?
I would like to compress the values that a field can take in my PostgreSQL database, but could not find a way to do it in a query while creating the table. For instance, let’s say I have a table which is named Books, and it contains some essential information about my books. The fields might be like: bo…
How to insert values into the following table by incrementing the date column by 1 day for the next 23 days?
I am using SQL Server 2014. I have a table names T1 (extract shown below): I need to update table T1 for period 2020-10-13 to 2020-11-04 with the following logic: All rows to be appended to the table will have the same values as those for ReviewDate on 2020-10-12 except the ReviewDate which will increment by …
How to force Postgres to calculate with numeric precision
I have a .net core application using dapper with Postgresql. Windows, PostgreSQL 12.0, compiled by Visual C++ build 1914, 64-bit When i do simple calculation in the select-statement, then i get different results if i do not provide fractions: 1258 1208 What’s the reason and what’s the best way to …
Order count per ID and calculate time between orders in BigQuery
I am working with customer purchase data and am trying to write a query in Google BigQuery that sorts all purchases by date and adds a purchase/order count per customer (order_count). Also, I would like to calculate a time-delay (in days) between the orders of one customer (purchase_latency). My query current…