I have this line data, where it also shows the status: approved, in progress, not yet started. I need to count how many lines are ALL APROVED based on the line colors. the data is similar to this: the query should show that there is only color (which is green) that all the status are approved, because red still have
Tag: aggregate-functions
Calculate percentage using SQL
I am trying to find how I can calculate Percentage from table below From the above table, I am hoping to get the data with percentage like below. However my SQL statement below returns all percentage …
Retrieving specific column data from SQL sub-query
My goal is to pull out the values shown in red in the picture. I used this query to pull the data together. The rows are associated via ActionID and filtered with the ‘AND’ conditions shown. SELECT […
Order by descending aggregation within window function in PostgreSQL
I have a dataset that features duplicate values of the the primary variable, something like the following: I have achived this by using the following code However, my desired output needs to be ordered such that counts is descending yet col1 remains partitioned, so that I can see, for example, which value from col1 has the highest number of counts.
Better way to find records meeting two different aggregate criteria?
I need to find customers that have a sum of credit transactions greater than or equal to a threshold amount and a sum of debit transactions less than or equal to the inverse of that same threshold amount. I also want to return the transactions whose aggregate transaction amount satisfies the credit and debit thresholds. I have come up with
Date distinct count over week
Im trying to get a distinct count of user ids logs per day with every week as a partition for the distinct identification. e.g. if one user logs on Friday/Saturday of week 1, and on Monday/Friday of …
How to assign a field name to an SQL Count in AWS Athena SQL
I’m still new to Athena. I think I got my database defined correctly, as shown in Example 1 below. However, when I run a count query, I get results unlike what I would expect. Example 1: Works Fine except count is called “_col3” Result: Example 2: syntax error This query shows a syntax error when I click “Run Query”: Answer
Use multiple but identical aggregate function
I’m trying to use two identical aggregate function is SQL Server, where I use COUNT(A) with some condition and COUNT(A) with another condition. For example I want to count all students enrolled in the course ABC, and the second count I want to count all students who have grade A and have enrolled in the same course ABC. But the
How to exclude certain values from a Query [SQL]
as the title states, an NotPrimID, can have two different values Example 1 and Example 2 IF: if NotPrimID does have both values, it should be automatically excluded from the query result. What i want: Query, that will deliever all the NotPrimID, that only have “Example 1” as a result, however if NotPrimID does have “Example 2” also as a
How to filter rows that has multiple condition MySQL
I have a table that contains my product details Now I want to write a query that gives me product_id(s) with this conditions: Brand = Intel model = Core i7 I’ve tried this one but it didn’t returns any rows, I guess I should use JOIN. Answer Use group by and having: Or better yet, using tuple equality: