What I’m trying to achieve is this: 1) Get the minimum value of a salary in the table for every department. 2) If this minimum value exists in the table at least two times for every department, then …
Tag: aggregate-functions
How to get a COUNT() value when GROUP BY has no row?
RDMS : MariaDB 10.1.23 MCRE : SQLFiddle: http://sqlfiddle.com/#!9/f32a01/1 Consider the following query : Without the GROUP BY clause, I know that COUNT() will return 0 if no row match the query. I also know that, if my GROUP BY “fails” (If i have no row to group by, in my example, if no row satisfy e.created_at > CURRENT_DATE – INTERVAL
Get the average of values in every specific epoch ranges in unix timestamp which returns -1 in specific condition in MySQL
I have a MySQL table which has some records as follows: I want to compute the average for every 10 epochs to see the following results: I saw some similar answers like enter link description here and enter link description here and enter link description here but these answers are not a solution for my specific question. How can I
How to use aggregate functions in SQL Server
I have a situation where I have a Customer table and I need to locate document numbers from a column which is structured as a string where the first 4 characters represent the type of document (e.g.,’…
Pivot table without crosstab/tablefunc
I have a table like this INPUT I want to be able to pivot this table in the following manner OUTPUT All the articles that I can find online pivot tables based on a second column. My ultimate goal is to get one records per ID. FINAL OUTPUT Here the values of the size, python, cpp, non-code columns are aggregated.
calculating percentage on multiple sql tables
There are 2 tables mobile and web Table name: Mobile Table name: web I need to calculate percentage of users who only visited : mobile, web and both. That is, the percentage of users who are only in the mobile table, only in the web table and in both tables. The sum should be 1. I tried using union but
How do I count the customers that made more than a purchase?
I have a table called order that looks like this: I am trying to display: 1.Total count of customers that bought 1 time only (that went to the store in one occasion, it could have been that they bought multiple items but it is only a one time event) 2.Total count customers that bought more than 1 time (that went
Weighted Average of Survey Questions
I have to calculate weighted average for all questions. Assuming there are 22 questions in a survey which has 5 options as 1,2,3,4,5 and NA. For example, 3 people took the survey (all 22 question) Assuming there are 10 NA responses (combined for all 3). So, denominator will be : 22*3 – 10 = 56 Numerator will be : 1*X1
How to select from a column with a list of ids in postgresql
I’ve got mytable1 with row_number integer and list_of_ids int[] column mytable2 with id integer and company text columns Example entry for mytable1 Example entry for mytable2 I need to feed back values from mytable2 into mytable1. This way the expected output would be Answer You need to unnest the lists of ids, join mytable2 using unnested ids and finally aggregate
Get count and grouping of foreign key
I have this product_user table which has foreign key product in it. I need to group and count all of the products from that table with the same IDs and get that product name so result of the query …