I am using SQL Server 2014 and I have the following T-SQL query which retrieves the dates of the first day of each month (based on my filters) from a Date Dimension Table: SELECT * FROM ( SELECT …
Tag: group-by
Hierarchical Data In Oracle SQL
I have tbl_parent like this in Oracle SQL, sample data is given below: Id(primary key) parentid childid 1 1 2 2 1 3 3 2 …
Oracle: Analytical functions Sub totals after each change in value
I have the following data (order of records as in the example): A B 1 10 1 20 1 30 1 40 2 50 2 65 2 75 1 89 1 100 from SQL: with x as ( select A, B from ( select 1 as A, …
SQL count rows with same value in column and group by id?
i have a table like this: i wonder if its possible to count the rows with same value and group them by id , but every time the code will return count 1 if i group them by id and not by value wanted output: Answer You need to count the value of the column value for each id: See
How to INNER JOIN only one row from second table
I have a issue joining only one row from the second table statement: SELECT ART.*, EAN.* FROM ART,EAN WHERE ART.ARTNR = ean.unit_artnr AND ean.typ = ‘LE4’; TABLE EAN has sometimes 2 …
How to sum up unique values using case statements having certain conditions
I have a table that may have the same item but with different sizes, I would like to count those items with more than one size (e.g. marvel shirt with S, M sizes will count as “1”), but still be able …
how to compute percentage in mysql/sql when 2 group by conditions are present
id title count organizer 1 music 4 2 2 sports 6 2 3 music 2 3 I have a derived table with the above structure. I need to compute the percentage of the number of events of each …
Find most recent row per user and day in sql query
I want to find the most recent purchase per customer for each date (a customer might make multiple purchases on a given date and I want the most recent for that date). My dataframe looks something …
One select statement with multiple Group BY on the same column
I have ‘TABLE_A’ like this: TVA Amount InvoiceID ———————- 22 | 10.00 | inv-12 22 |-14.00 | inv-13 25 | 24.00 | inv-14 25 |-36.00 | inv-15 25 |-25.00 | inv-16 25 | 18.50 | inv-…
SQL How to link lowest row from another select
I searching since a week for this problem. I try many code and I’m not able to get a correct answer, here’s the problem : I have a table of seller that have each time a customer contact this seller, …