If I have a table like the following which is the number of records with a given label grouped by a certain category (in this case Male, Female), How would I transform it into a table that keeps the top x (e.g. 5 records) for each category, when the rows are sorted by number descending, and sums the remaining rows
Tag: group-by
How to display values from different tables in certain time frame MYSQL
I have attached the tables that are included in this question for MYSql. My question states: First and last names of the top 5 authors clients borrowed in 2017. My code so far: I think so far my code just displays the top 5 Author ID in 2017 but I can’t figure out how to display the names. I see
I am getting a “subquery returning multiple rows” error. I want to return multiple rows however
I want to have a subquery which returns multiple rows in MySQL. I used the IN function as well. However i am getting a “subquery returning multiple rows” error. I have attached an image of the tables used and the desired output Here is my SQL code: Answer You seem to want conditional aggregation:
UNION ALL not combining rows
I have this table called “valores_indices” where it imports stocks values every 1 hour, I need to get the values from each monitored stock at 8am and 6pm, those being respectively my “vlrAberto” and “vlrFechado” selects I don’t get why these are not merging, I’ve done it before, any help would be appreciated since I’m running out of ideas, I’ve
ORA-00937 not a single-group group function when using CASE Condition
I’ve been searching for a few hours now, on how to resolve an ORA-00937: not a single-group group function and none of them seem to explain why I am getting the error. My understanding is, when applying an aggregate function in the select statement on one or more columns, than you should include the columns that are not aggregated in
Hive – Split and count values by delimiter – lateral view explode
I have a following Hive table I need to split and get the count values of each item in item_val column Expected output I tired below count but values are not getting delimited properly. Please help! Answer In Hive, one option is to use the lateral view syntax:
Merging query from same table into different columns
I’m having an issue querying a table for some information. Basically the way data was stored in the table, for every customer, its information was stored vertically and so on for others. In my case I want to display in separate columns for example only the ‘Company’ and ‘StreetAddress’ values from all their information for each CustomerId. I tried joins,
Need a Query to fetch distinct data from a table in my sql
I have a table History which contains below columns: I need a query to fetch data from a table in a manner that every user should return only one row for the day even if a user has more than one entry for a day The required resultset should be as below : Answer You can group by User and
I need to find the average of all records (Qty) which related Supplier numbers (SNo) if there have at least only one record
I need to find the average of all records (Qty) which related Supplier numbers (SNo) as S1, S2 ..etc. even if there have at least only one record to true the condition this query select only one record and the query checking condition before get the average this is my table : I need to select average qty from the
Pivot data row to header using SQL in Postgresql
I get this result using SQL request: NBR_TYPE Count ———————– 0021 20 0022 19 0023 13 But i want result like this : 0021 …