Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question The query below gives me top 3 services for 6th June 2021. I want to repeat this for each day …
PostgreSQL UPSERT (INSERT … ON CONFLICT UPDATE) fails
I have a row in my postgresql database that I want to update. My code generates this SQL statement to insert else update the one field that’s changed: What I don’t understand is that I can select that one row and it is present with a non-NULL num_syncs. But the UPSERT is failing because it doesn&#…
How to combine multiple records in one in SQL
I have a SQL table that looks something like this: OP ID First name Last name Phone number I 123 John Smith 888-555 U 123 777-555 I have to combine this rows through select query into something like this: ID First name Last name Phone number 123 John Smith 777-555 I have trouble writing query because my only …
How to union current table and history table order by recent edit
I am currently working on preparing audit table and the output structure I am planning to have is, latest record from current table and followed by associated(id) records from history table for all the records. So that user can see the latest changes and its history. At present I am using UNION of two tables …
How do I return a row with 0 if the group by has 0 records?
I have this alert_levels table: Then I have this alerts table The alert_level_id in the alerts table is a foreign key of id from the alert_levels table. What I want is to count the number of occurences of each alert_type grouped by the alert_level_id whithin a chosen time period. And if there is no occurency …
How to distribute stock quantity from a single cell to different aging brackets based on the the aging brackets quantities?
We have a table with item codes and current stock quantity and quantities in aging brackets whenever they were received (1-90, 91-120, etc) as follows: I need to distribute the STOCK_AS_ON_DATE quantity in the age brackets until no balance quantity is left. Example: Item A’s STOCK_AS_ON_DATE is 40377, i…
SQL query to get number of clients with last statement equal connected
I need to make a SQL query table ‘records’ structure: It has to show the following: Could somebody help? sample data: desired output: I tried something with sub queries, but it obviously doesn’t work: How should I use the inner selects? I must write a poem, because most of my post is a code.…
Copy table from one database to another in multiple threads in C++
There is a huge SQL table in Postgres Database. I’d like to copy the contents of it to another different database (SQL Server) using C++. I have written a single-thread application and it works fine. I decided to use multiple threads to increase the performance of reading and writing data. Here in the c…
Default value data type does not match data type for column DATES_DATE
I’m trying to make a table in Snowflake but it is giving me error due to default value. This seems to work fine in Oracle but not Snowflake. Error- SQL compilation error: Default value data type does not match data type for column DATES_DATE Please let me know where I’m going wrong. Answer Please …
SQL Count Customers where Products are the same
I have a problem. I have a SQL-database named customers with the 3 columns Country, CustomerID and Product. With that database, I want to count all the customers which bought the products bike, flask and helmet but grouped by the country as you can see in the following picture. Is there a chance you can help …