group-concat

Mysql - optimisation - multiple group_concat & joins using having

做~自己de王妃 提交于 2019-12-24 16:22:14
问题 I've looked at similar group_concat mysql optimisation threads but none seem relevant to my issue, and my mysql knowledge is being stretched with this one. I have been tasked with improving the speed of a script with an extremely heavy Mysql query contained within. The query in question uses GROUP_CONCAT to create a list of colours, tags and sizes all relevant to a particular product. It then uses HAVING / FIND_IN_SET to filter these concatenated lists to find the attribute, set by the user

select * transform row value as table column name

跟風遠走 提交于 2019-12-24 14:36:06
问题 I am trying to transform row value as column name. After searching on stackoverflow I learned that it can be done by using GROUP_CONCAT(). I tried it but no result. what I want?? i have a table like this : id | staff_id_staff | leave_type_id_leave_type | days 1 | 41 | Casual | 7 2 | 41 | Earned | 1 3 | 41 | Sick | 4 and want result like this: Casual | Earned | Sick 7 | 1 | 4 Please note: I dont know the value of leave_type_id_leave_type (it will be anything) Here is the code of leave_remain

group_concat: have values display in a new line on the browser

Deadly 提交于 2019-12-24 11:27:07
问题 I have a simple query that i'm using MYSQL'S GROUP_CONCAT() function: SELECT `ProductID` , GROUP_CONCAT( Description SEPARATOR "\n" ) AS description FROM Features GROUP BY `ProductID` The above query works fine on the phpmyadmin interface i.e. the values are returned displayed in a new line as shown below: However, when i run the query in the browser, the values are separated by a space and not in a new line as i would wish: i should mention i have even tried using the br tags as the

Multiple Table Joins with Group_Concat where some records don't exist in all tables

不问归期 提交于 2019-12-24 09:55:02
问题 I am trying to do a fairly complex (for me) query that will grab a Description field from a Main Table and then append it with titles and values from related Look-Up-Tables. Not all records have records in the Look-up tables. I'll pose further questions as subsequent questions as I go along, but to start my issue is that only those records with values in all the tables show up. http://sqlfiddle.com/#!9/09047/13 (null) This is Record 2 Text Color : Red Fruit : Apple (null) If I use Concat_WS I

How to multiple concatenate values from multiple relation tables in a single mysql query

可紊 提交于 2019-12-24 06:48:51
问题 I have a big issue for my "traveling offer" project, working 99% OK, but not 100%. I have main table with offers, where each offer can have set multiple department cities as well as multiple destination cities (this is reduced sample with reduced columns). For example, I'm offering some travels from England, where department cities can be from London, Leeds and Manchester. Destination cities are Prague, Bratislava, Budapest and Belgrade. Offer 1 is set to department cities London or Leeds,

db field(GROUP_CONCAT) as array

喜夏-厌秋 提交于 2019-12-24 03:46:04
问题 MY tables.. articles fields: id name cats fields: id name article_cats fields: id article_id cat_id I have this sql: SELECT a.id AS article_id , a.name AS article_name , COUNT( c.id ) AS num_categories , GROUP_CONCAT( c.name ) AS categorie_names FROM articles AS a LEFT JOIN article_cats AS ac ON ( a.id = ac.article_id ) LEFT JOIN cats AS c ON ( ac.cat_id = c.id ) GROUP BY a.id and it provide this table structure: what i need is, to get categories id and name in array, so categorie_names will

Group by X or Y?

元气小坏坏 提交于 2019-12-23 12:48:26
问题 I'm trying to figure out how to GROUP BY on multiple columns. I want to group items when the SSN or the address matches. For example, here are three records: account_number | name | ssn | address ---------------+--------------+-------------+---------------------- 23952352340 | SMITH INC | 123-45-6789 | P.O. BOX 123 3459450340 | JOHN SMITH | 123-45-6789 | 123 EVERGREEN TERRACE 45949459494 | JANE SMITH | 395-23-1924 | 123 EVERGREEN TERRACE And here's what I'd like to end up with: names --------

Using php to return GROUP_CONCAT('column x') values

喜夏-厌秋 提交于 2019-12-23 09:49:29
问题 I am trying to use PHP to return SQL values into an HTML table. I am able to get every column to populate without a problem except for the last column, "GROUP _ CONCAT (provision_id)." Relevant code: <?php global $wpdb; $wpdb->show_errors(); $contents = $wpdb->get_results( $wpdb->prepare("SELECT salaries.id, name, remaining, contract_value, GROUP_CONCAT( provision_id ) FROM salaries LEFT JOIN contracts ON contracts.id = salaries.id GROUP BY salaries.id")); ?> [table header stuff...] <?php

New column in pandas - adding series to dataframe by applying a list groupby

好久不见. 提交于 2019-12-23 08:11:56
问题 Give the following df Id other concat 0 A z 1 1 A y 2 2 B x 3 3 B w 4 4 B v 5 5 B u 6 I want the result with new column with grouped values as list Id other concat new 0 A z 1 [1, 2] 1 A y 2 [1, 2] 2 B x 3 [3, 4, 5, 6] 3 B w 4 [3, 4, 5, 6] 4 B v 5 [3, 4, 5, 6] 5 B u 6 [3, 4, 5, 6] This is similar to these questions: grouping rows in list in pandas groupby Replicating GROUP_CONCAT for pandas.DataFrame However, it is apply the grouping you get from df.groupby('Id')['concat'].apply(list) , which

New column in pandas - adding series to dataframe by applying a list groupby

房东的猫 提交于 2019-12-23 08:11:11
问题 Give the following df Id other concat 0 A z 1 1 A y 2 2 B x 3 3 B w 4 4 B v 5 5 B u 6 I want the result with new column with grouped values as list Id other concat new 0 A z 1 [1, 2] 1 A y 2 [1, 2] 2 B x 3 [3, 4, 5, 6] 3 B w 4 [3, 4, 5, 6] 4 B v 5 [3, 4, 5, 6] 5 B u 6 [3, 4, 5, 6] This is similar to these questions: grouping rows in list in pandas groupby Replicating GROUP_CONCAT for pandas.DataFrame However, it is apply the grouping you get from df.groupby('Id')['concat'].apply(list) , which