I have the following criteria that won’t run. I have tried: SELECT Main_ID AS [First_Custom_Column], CASE WHEN Column_1 = ‘Y’ AND SUM(CASE WHEN Column_3 > 1 THEN …
Tag: sql
Advice on database design – SQL recipe editor
I want to build an SQL-based recipe editor for a brewery. I have n recipes: Every recipe is part of a category. Every category has a list of steps. Steps can be reused in the same category several times and in different orders. Every step has n set-points. Setpoints change based on the recipe. The same steps …
Return all rows from one table, and match rows from another table
I have the following two tables: ExchangeRate (T1): CurrencyCode Rate CHF 6.9660 EUR 7.4445 GBP 8.2569 NOK 0.6686 Customer (T2): CustomerNo Name …
SQL question, using an aggregate function inside a made table from a query [closed]
I feel like I’m not understanding how to do the syntax for this. SELECT main_category, COUNT(main_category) AS ‘Kickstarters’, CAST(SUM(if(state = ‘successful’, 1, 0)) AS SIGNED) AS ‘…
SQL – Aggregate all EXCEPT group
Consider the following sample table from a soccer tournament (let’s call this table matches) +———-+———+————–+ | match_id | club_id | goals_scored | +———-+———+———-…
Distinct count with dynamic start date and end date
I have this dataset Webinar: id title start end 1 A 2020-01-01 10:00 2020-01-01 12:00 2 B 2020-01-02 15:00 2020-01-02 17:30 User_activity id user_id …
Multiple aggregate calculations using Group by
I have a dataset, df1, where I would like to: Take the average of the TotalB column based upon grouping the TotalB column. I would then like to take this new column and subtract the free value to …
Suitable Index for improving Top N recent queries with tags
I am designing the schema of a database in PostgreSQL which would contain posts like Stack Overflow with tags. Users would search recent posts by different tags. From my research, I found that …
Querying a cte – The multi-part identifier could not be bound. How do I fix this so I can query the table? New to SQL accounting background
I am trying to extract a dataset which joins 3 tables Employee E AbsenceTypes AT AbsenceBalance AB In the data set I need the most recent record from AB.BalanceTime for each AB.EmployeeUID by AB….
How can I compare rows of data in an array based on distinct attributes of a column?
I have a tricky student work in spark. I need to write an SQL query for this kind of array: There are more departments and accordingly loans for each department both for males and females. How can I compute a new array where Female’s loans are more than Male’s loans per department and print/show only the depa…