group-concat

MYSQL select query return list of months as string from between start/end date

自古美人都是妖i 提交于 2019-12-10 11:43:39
问题 There are two main fields Startdate and Enddate in Contract table I want to give result as extra column called description to represent month come between Contract start and end. see bellow table and result which I require Table : Contracts ------------------------------ ID | START | END | ------------------------------ 1 | 2016-05-01 | 2016-07-31 | 2 | 2016-04-01 | 2016-08-31 | 3 | 2016-01-22 | 2016-02-25 | ------------------------------ Here I need result as per bellow formate, one extra

GROUP_CONCAT with JOINLEFT in Zend Db Select

橙三吉。 提交于 2019-12-10 04:12:08
问题 Assuming that I have 2 tables articles id title 1 Article 1 2 Article 2 Images id article_id image 1 1 a.png 2 1 b.png 3 2 c.png 4 2 d.png All that I want is retreive all articles with their images. For example: article_id title images 1 Article 1 a.png, b.png 2 Article 2 c.png, d.png How could I do that with Zend_Db_Select? I tried something like this but had no luck: $select = $this->getDbTable()->select()->setIntegrityCheck(false)->distinct(); $select->from(array('a'=>'articles')) -

doctrine2 and group_concat

元气小坏坏 提交于 2019-12-09 01:00:17
问题 i've been looking through the docs/google and didn't find any solution. is there any way to execute or imitate GROUP_CONCAT using doctrine2 (DQL) without native mysql? eg.: SELECT u.id, u.name, [GROUP_CONCAT(...)] AS user_messages FROM models\Users u LEFT JOIN models\Messages m GROUP BY u.id to get GROUP_CONCAT(m.id,'|',m.title SEPARATOR ':') right now i'm using the createNativeQuery() to run it, but i'm looking for a doctrine2 solution. thanks in advance 回答1: Yes this is possible with

mysql group_concat group by on multiple fields

谁说我不能喝 提交于 2019-12-09 00:20:08
问题 I have a Table member with member_id , member_name , club_name , region , zone , email as fields. I am using the MySQL group_concat function like SELECT group_concat(distinct m.email SEPARATOR ', ' ) from member m group by m.club_name This is working fine. But I would like to be able to group_concat on other fields without creating additional queries. Is it possible to supply the other fields as parameter? member_id member_name club_name region zone email 1 member1 A 1 1 email1@example.com 2

Join one row to multiple rows in another table

爷,独闯天下 提交于 2019-12-08 23:04:13
问题 I have a table to entities (lets call them people) and properties (one person can have an arbitrary number of properties). Ex: People Name Age -------- Jane 27 Joe 36 Jim 16 Properties Name Property ----------------- Jane Smart Jane Funny Jane Good-looking Joe Smart Joe Workaholic Jim Funny Jim Young I would like to write an efficient select that would select people based on age and return all or some of their properties. Ex: People older than 26 Name Properties Jane Smart, Funny, Good

GROUP_CONCAT multiple fields with a different separator

梦想的初衷 提交于 2019-12-08 16:58:41
问题 Is it possible to do something like: GROUP_CONCAT(user, price SEPARATOR ', ') AS items The result is John3.99, Mike24.99 What I need is something like: John - 3.99, Mike - 24.99 Basically use another type of separator for price field. 回答1: GROUP_CONCAT(CONCAT(user, ' - ', price) SEPARATOR ', ') AS items Or just GROUP_CONCAT(user, ' - ', price SEPARATOR ', ') AS items 回答2: Try this way GROUP_CONCAT( DISTINCT CONCAT(user,',',Price SEPERATOR) ORDER BY items SEPARATOR ';' ) 来源: https:/

Mysql return more than one row

天大地大妈咪最大 提交于 2019-12-08 16:38:28
问题 I have this query. SELECT notes.id,enter.name as 'enter_name',step.title as 'flow status',notes.user_name as user_created,notes.created,notes.rel_client_id,td_doc_nr.value_string as 'document number',enter.enter_code, IF(!ISNULL(td_doc_nr.value_string), (SELECT GROUP_CONCAT(product_name SEPARATOR ',') from notes d join note_bundles b on b.note_id = d.id join note_products p on p.doc_bundle_id = b.id join note_product_get_fields f on f.doc_product_id = p.id join note_product_get_field_data fd

SELECT WHERE IN with GROUP_CONCAT as input

别说谁变了你拦得住时间么 提交于 2019-12-08 10:28:28
问题 Please read this before continuing: Filter an unfiltered table against a whitelist table So, I currently have a whitelist table set up as shown in the referenced link, and I'm encountering yet another issue brought up by said table, that is, to check the UNIQUENESS of each column. As MySQL's specification, it is not possible to set NULL column as UNIQUE, so, I've decided to come up with a different solution to check if rows are duplicated or not by using a SELECT GROUP BY query as follows.

SQL select query to merge rows

此生再无相见时 提交于 2019-12-08 07:52:49
问题 I have a single MySQL database: ------------------------------------------------------------------- Email | Name | Tag ------------------------------------------------------------------- test@test.com |Test Person | TagOne test@test.com |Test Person | Tag Two ------------------------------------------------------------------- Need an SQL query that will return ------------------------------------------------------------------- Email | Name | Tag -----------------------------------------------

Using MySQL GROUP_CONCAT or PIVOT on multiple joined tables

*爱你&永不变心* 提交于 2019-12-08 01:54:40
问题 ISSUE I'm working on a content management system for a school, and I'd like to be able to create a view of multiple joined tables. In addition to joining the tables, I need to perform a PIVOT or GROUP_CONCAT (or some other function) in order to take multiple rows from each table and use them as columns in the view. To help visualize, here is a simplification of what I'm working with: SETUP STRUCTURE: DROP TABLE IF EXISTS `date`; CREATE TABLE `date` ( `col_pkid` int(11) NOT NULL AUTO_INCREMENT