2017-03-17 3 views
0

Ich habe 4 Tabelle, dieVerbinden Sie mehrere Tabelle mit mehreren Gruppen concate Mysql

trxn_tbl ist:

 
works_id works_date 
1   3/17/2017 
2   3/19/2017 
3   3/18/2017 

apps_txn_tbl:

 

id works_id apps_name 
1 1   JoinBDApps 
2 1   PMS 
3 1   CADET COLLEGE 
4 2   JoinBDApps 
5 2   PMS 
6 2   CADET COLLEGE 
7 3   JoinBDApps 
8 3   PMS 
9 3   CMH 

work_loc_trxn_tbl:

 
id works_id loc 
1 1   DC 
2 2   AITSO 
3 3   DR 

works_type_txn_tbl:

 
    id works_id works_type 
    1 1   Trobleshooting 
    2 1   Software Upgrade 
    3 2   Trobleshooting 
    4 2   License Key Update 
    5 3   Trobleshooting 
    6 3   License Key Update 

Wenn ich Abfrage Mysql Said laufen: MySQL sagte: Dokumentation

1055 - Expression # 3 von SELECT-Liste ist nicht in GROUP BY-Klausel und enthält nicht aggregierten Spalte 'dcapp_db.work_loc_txn_tbl.loc', das ist funktional nicht abhängig von Spalten in der GROUP BY-Klausel; dies ist unvereinbar mit sql_mode = only_full_group_by

Aber ich will diese Art:

 
works_id Works_date work_type       appsname          loc 
1   3/17/2017 Trobleshooting, software upgrade JoinBDapps, PMS, CADET COLLEGE      DR 
2   3/19/2017 Trobleshooting, License Key Update JoinBDapps, PMS, CADET COLLEGE     AITSO 
3   3/18/2017 Trobleshooting, License Key Update  JoinBDApps, PMS, CMH       DR

Wo Problem ist und ich brauche das Tischsystem zu ändern oder abfragen Bitten helfen Sie mir .... Meine Frage ist: "Meine Abfrage ist :

 
SELECT trxn_tbl.works_id, trxn_tbl.works_date,work_loc_txn_tbl.loc,GROUP_CONCAT(works_type_txn_tbl.works_type SEPARATOR ',')as worktype,GROUP_CONCAT(apps_txn_tbl.apps_name SEPARATOR ',')as appname FROM trxn_tbl JOIN works_type_txn_tbl on works_type_txn_tbl.works_id=trxn_tbl.works_id JOIN apps_txn_tbl on apps_txn_tbl.works_id=trxn_tbl.works_id JOIN work_loc_txn_tbl on work_loc_txn_tbl.works_id=trxn_tbl.works_id GROUP BY trxn_tbl.works_id; 
"

Antwort

0
  1. works_id, works_date muss loc in GROUP BY hinzuzufügen.
  2. Sie haben zwei GROUP_CONCAT in einer Abfrage verwendet, dann hat diese Abfrage nicht genug Spalten zu GROUP BY, also hat GROUP_CONCAT doppelte Inhalte.

Try this:

SELECT 
    trxn_tbl.works_id, 
    trxn_tbl.works_date, 
    work_loc_txn_tbl.loc, 
    GROUP_CONCAT(
     DISTINCT works_type_txn_tbl.works_type SEPARATOR ',' -- add DISTINCT 
    ) AS worktype, 
    GROUP_CONCAT(
     DISTINCT apps_txn_tbl.apps_name SEPARATOR ',' -- add DISTINCT 
    ) AS appname 
FROM 
    trxn_tbl 
INNER JOIN works_type_txn_tbl ON works_type_txn_tbl.works_id = trxn_tbl.works_id 
INNER JOIN apps_txn_tbl ON apps_txn_tbl.works_id = trxn_tbl.works_id 
INNER JOIN work_loc_txn_tbl ON work_loc_txn_tbl.works_id = trxn_tbl.works_id 
GROUP BY 
    trxn_tbl.works_id, 
    trxn_tbl.works_date, 
    work_loc_txn_tbl.loc 

SQLFIDDLE

+0

Dank Es funktioniert ...... –

+0

Ihr Vorschlag ist mir so hilfreich –

+0

Ist es möglich, mehrere Gruppen Concat in meiner Anfrage hinzufügen? Ich brauche 6 oder 6 Gruppen in einer Abfrage ... Ist das möglich? –

Verwandte Themen