I have a simple BOM table that contains a parent and a child column. Every row contains values. There are no blanks. To bring that table into a BI-Tool I need to add blank values for the parents, like …
Tag: sql
For the GROUP BY function in PostgreSQL, how to set a value if any rows meet a condition?
I have a use case that needs to set a value if any rows meet a condition in the GROUP BY function of PostgreSQL. The example is as following. The table contains the following data. I want to run the SQL query to group by based on id. If any rows of the same id have type as ‘A’, then
Query which outputs the number of athletes that voted for someone in the same athletePosition? [closed]
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 Like the title says, SQL query which outputs the number of athletes that voted for someone in …
SQL Order By on multiple columns containing Nulls
I have a table containing multiple columns, and I want to order by three of the columns within the table. I want to order by lot, then unit, and lastly number. Lot and Unit can contain nulls (need them listed at the bottom) whereas Number column does not contain Null. I’ve tried a bunch of case statemen…
Display duplicate row indicator and get only one row when duplicate
I built the schema at http://sqlfiddle.com/#!18/7e9e3 I would like to write a query that would produce the following result characteristics : Returns only one owner per boat When multiple owners on a single boat, return the youngest owner. Display a column to indicate if a boat has multiple owners. So the fol…
Aggregation level is off (Postgresql)
I have Order data for 2 customers and their order. And I am trying to calculate what the sum for the price is for every customter for that specific order only for product N Table: This is my query: For some reason I do not understand it gives me several rows per same customer. I am trying to get only
Create Continuous Enrollment islands for a certain sub-population
My end goal is to create islands of continuous enrollment days for each CLIENTID for a single sub-population: ‘Adult Expansion’ for calendar years 2019 and 2020. A CLIENTID can be associated with …
Get sum of column with distinct id in SQL
I am trying to get sum of the amount on distinct ext_id. Id Ext_id amount 1 234 5 2 234 5 3 235 10 4 236 8 5 236 8 Select SUM(amount) from Table1 — this will get me sum of all => 36 I want just sum of distinct Ext_id which should be 23. Can someone help me with this?
SQL JOIN, all from t1 and all from t2 except what’s common to t1
I need all entries from Table A and all entries from Table B that are NOT common to table A. I have 6 common fields. How do I go with this? I tried select … from Table A left join Table B, it missed some values from Table A. Tried also right join, full join…Any pointers on how to do
JPA query is throwing a ‘not found’ error for column that isn’t in query
I’m trying to call for only specific columns in my DB but the query is throwing an error saying that the next column is not found (even though it’s not in the query) Is there a problem in the join that’s doin this? I’m a bit perplexed as to this problem. JPA Query from ConnectionReques…