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…
Tag: sql
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 …
Joining tables based on datetime2 predicate
How do I join tables A and B (see pic) on TripID and where TimeTriggered is between SegmentStart and SegmentEnd? I could try: However since BETWEEN is inclusive on both ends it would join alarm B to both segment 1 and 2. I could try >= AND < but it would leave out alarm C. I could try > AND
Postgres recursive queries and window functions to produce tree from table
Let’s say I have the following data. I got the request to produce a table with a single column in which categories and subcategories appear arranged like this. I don’t understand how to complete the task with the requirements established by my client (especially the first one). These are: I should…
SQL not using ALIAS column for calculation
Question Statement – From the given trips and users tables for a taxi service, write a query to return the cancellation rate in the first two days in October, rounded to two decimal places, for trips not involving banned riders or drivers. Question code on Oracle SQL. My Solution Code is below. However,…
Subquery on SELECT with conditional WHERE clause after it
So I have three tables, news : topics : and news_topics : And I want to return it like these : I succeed on returning that value using this query But there is one flaw to that query, on the above result there are one row that contains null topics. When I add AND topics IS NOT NULL after it
Is there any syntactic sugar to using group by columns 1,2,3,…,n in SQL?
I know it isn’t a “good way of doing things”, but we use the following notations in many of our SQL queries : I was wondering if there is an even more succinct way of writing it, e.g. GROUP BY 1-n (Group by col_1 to col_n) Answer Assume you have table with dozen or more columns Consider belo…