GROUP BY + CASE statement

Your query would work already – except that you are running into naming conflicts or just confusing the output column (the CASE expression) with source column result, which has different content. … GROUP BY model.name, attempt.type, attempt.result … You need to GROUP BY your CASE expression instead of your source column: … GROUP BY model.name, … Read more

Postgres – aggregate two columns into one item

You could avoid the ugliness of the multidimentional array and use some json which supports mixed datatypes: SELECT user_id, json_agg(json_build_array(friend_id, confirmed)) AS friends FROM friends_map WHERE user_id = 1 GROUP BY user_id Or use some key : value pairs since json allows that, so your output will be more semantic if you like: SELECT user_id, … Read more

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

for SQL Server 2017 and up use: STRING_AGG() set nocount on; declare @YourTable table (RowID int, HeaderValue int, ChildValue varchar(5)) insert into @YourTable VALUES (1,1,’CCC’) insert into @YourTable VALUES (2,2,’B<&>B’) insert into @YourTable VALUES (3,2,’AAA’) insert into @YourTable VALUES (4,3,'<br>’) insert into @YourTable VALUES (5,3,’A & Z’) set nocount off SELECT t1.HeaderValue ,STUFF( (SELECT ‘, … Read more

SELECTING with multiple WHERE conditions on same column

You can either use GROUP BY and HAVING COUNT(*) = _: SELECT contact_id FROM your_table WHERE flag IN (‘Volunteer’, ‘Uploaded’, …) GROUP BY contact_id HAVING COUNT(*) = 2 — // must match number in the WHERE flag IN (…) list (assuming contact_id, flag is unique). Or use joins: SELECT T1.contact_id FROM your_table T1 JOIN your_table … Read more

Spark SQL: apply aggregate functions to a list of columns

There are multiple ways of applying aggregate functions to multiple columns. GroupedData class provides a number of methods for the most common functions, including count, max, min, mean and sum, which can be used directly as follows: Python: df = sqlContext.createDataFrame( [(1.0, 0.3, 1.0), (1.0, 0.5, 0.0), (-1.0, 0.6, 0.5), (-1.0, 5.6, 0.2)], (“col1”, “col2”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)