I have a query that pulls the total number of records grouped by the year and length of characters in the identification number. I want to add a column that calculates the percentage of this total against the total for each record year. This is the query that I am using, and so far I’m able to pull the year,
Tag: aggregate-functions
How to get the average of a column in MySQL
I’m trying to find a way to calculate the average of a column (as a double/float or decimal). I’ve found the AVG function in MySQL documentation but I can’t get it to work. Currently I’ve got the following code: Now for some reason this does not work. It returns “Unable to cast object of type ‘System.Int64’ to type ‘System.Double’.” The
on SQL can I have a ratio column based on a count of multiple parameters?
On this query here, I get the following result in the image provided below. However I want to take it a step further and turn the count into a ratio of wins / total wins. However when I use the second query (at the bottom) I get an error invalid use of the group function. To explain, the count is
Access Bare Columns w/ Aggregate Function w/o adding to Group By
I have 2 tables in postgres. users auth0_id email 123-A a@a 123-B b@b 123-C c@c auth0_logs id date user_id client_name abc-1 021-10-16T00:18:41.381Z 123-A example_client abc-2 … 123-A example_client abc-3 … 123-B example_client abc-4 … 123-A example_client abc-5 … 123-B example_client abc-6 … 123-C example_client I am trying to get the last login information (a single row in the auth0_logs table
Obtain Name Column Based on Value
I have a table that calculates the number of associated records that fit a criteria for each parent record. See example below: note – morning, afternoon and evening are only weekdays What I am trying to achieve is to determine which columns have the lowest value and get their column name as such: Here is my current SQL code to
How to create a derived attribute column in sql which is sum of other two existing columns
I want to have a column selling_price which is sum of scost and dcost. Answer You can use MySQL generated columns for it. Reference Doc
Find 5 greatest totals after summing (quantity x value) for each qualifying user
I currently have a table which displays the inventory values of users. It works, but it displays all users and their inventory values in a random order. I’m wanting to limit the table to the top 5 descending inventory values only. This data cuts across three tables: DB Fiddle Users Inventories (contains a row for each item a user has
Aggregated row count differences between tables
I have two MySQL tables A and B both with this schema ID entity_id asset asset_type 0 12345 x 1 .. ……… ….. ………. I would like to get an aggregated top 10/50/whatever entity_ids with the largest row count difference between the two tables. I think I could do this manually by just getting the highest row count by entity_id
SQL total for each row combination
Are there any types of aggregate functions that could help calculate the following? If I have the following data, I want the sum total for each duplicated row. The output would provide total number each row occurs: Answer Why not good old group by and count?
How do I merge two SELECT queries with different WHERE clauses
I’m trying to write query on two different selects with different WHERE clause and using GROUP BY. I browsed for examples but mine is different since I have multiple fields for SELECT. Here is example data: These are the queries I would like to merge: I tried 2 methods as under: Both give Error: Please guide Answer seems like you