I have tables like this: SQLFIDDLE I’m trying to count how many products are in each category SELECT `category_id`, `category_name`, IFNULL(count(*),0) cat_stat FROM `product_to_categories` …
Tag: sql
How to sum transaction amounts for different time intervals in sql server?
Let say I have table called Transactions and have 3 following columns: Customerid TranscationDate TransactionAmount So I need to sum transaction amounts for each customer in different date intervals. …
How do a pivot on sql server on one column but renamed dynamics column
I’ve a table of prices With Reference, Price Category (Ex professional/Customer…) , the weight and the price Each article have X lines for same Reference, Price Category depend of weight I Want a return with Reference, Price Category, Price1,Price2… I try to adapt codes I’ve found but …
Updating joint query in Oracle
I’m trying to update the name on the trade table according to the user table however as we have so many trades I don’t want my query to update each and every trade. only the ones that have the …
Max and Avg debt days over a period of time
I have invoices pending payment, every invoice has two dates, first when the invoice is required to pay and the other when the invoice is paid. I want to know in a period of time the max debt and the …
Grouping shift data by 7-day windows in SQL Server 2012
What I want to do is to calculate the number of shifts and hours worked by each employee in any given 7-day period. In order to achieve this, I need to identify and group ‘islands’ of shifts. Note …
SQL count products
I have table: name product john beer john milk john tea john beer emily milk emily milk emily tea john beer i need select from this table, when output will be: name …
Assign new value to every unique number in SQL Server
I am new to SQL Server and trying to do some operations Sample data: Amount | BillID ——-+——- 500 | 10009 500 | 1492 350 | 15892 222 | 15596 899 | 20566 350 | 9566 How can …
Compare SQL scalar function result to a column in SQL
I have this query Here I need to compare the result of function i.e dbo.GetTopEmployerName() with x4.code. I need to check if they are not same. Answer Wrap your query up in a derived table:
Specific hierarchy geography
I have a table geography with three levels I need to display the level3 only for level2 = France, Benelux and for the other countries level2 = level 3 Result Example: Answer