All Questions

749
votes
28answers
689623 views

SQL select only rows with max value on a column

I have this table for documents (simplified version here): +------+-------+--------------------------------------+ | id | rev | content | +------+-------+------------...
155
votes
28answers
271963 views

Function to Calculate Median in SQL Server

According to MSDN, Median is not available as an aggregate function in Transact-SQL. However, I would like to find out whether it is possible to create this functionality (using the Create Aggregate f...
64
votes
2answers
73054 views

Does T-SQL have an aggregate function to concatenate strings?

Possible Duplicates: Implode type function in SQL Server 2000? Concatenate row values T-SQL I have a view which I'm querying that looks like this: BuildingName PollNumber -----------...
16
votes
3answers
8120 views

Two SQL LEFT JOINS produce incorrect result

I have 3 tables: users(id, account_balance) grocery(user_id, date, amount_paid) fishmarket(user_id, date, amount_paid) Both fishmarket and grocery tables may have multiple occurrences for the same ...
28
votes
1answers
15248 views

PostgreSQL: running count of rows for a query 'by minute'

I need to query for each minute the total count of rows up to that minute. The best I could achieve so far doesn't do the trick. It returns count per minute, not the total count up to each minute: S...
1
votes
3answers
328 views

How can I simplify this game statistics query?

This code works as expected, but I it's long and creepy. select p.name, p.played, w.won, l.lost from (select users.name, count(games.name) as played from users inner join games on games.player_1_id ...
66
votes
5answers
83330 views

Optimal way to concatenate/aggregate strings

I'm finding a way to aggregate strings from different rows into a single row. I'm looking to do this in many different places, so having a function to facilitate this would be nice. I've tried solutio...
16
votes
2answers
5571 views

SQL Query to get aggregated result in comma seperators along with group by column in SQL Server

I need to write a sql query on the table such that the result would have the group by column along with the aggregated column with comma separators. My table would be in the below format |```````...
18
votes
4answers
12876 views

SPARK SQL replacement for mysql GROUP_CONCAT aggregate function

I have a table of two string type columns (username, friend) and for each username, I want to collect all of it's friends on one row, concatenated as strings ('username1', 'friends1, friends2, friends...
72
votes
2answers
45555 views

Apply multiple functions to multiple groupby columns

The docs show how to apply multiple functions on a groupby object at a time using a dict with the output column names as the keys: In [563]: grouped['D'].agg({'result1' : np.sum, .....: ...

Previous Next