Created
August 8, 2017 07:28
-
-
Save murachi1208/ba97fb9610f5576aa01dffbd381b02ee to your computer and use it in GitHub Desktop.
いまさら MySQL で group_concat 使い複数レコードを1行にまとめる ref: http://qiita.com/murachi1208/items/2bdc8b5f65b741a667c3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach ($ret_array as $key => $value ) { | |
$sql = <<< EOM | |
desc $value; | |
EOM; | |
$stmt = $pdo->query($sql); | |
$koumoku = ""; | |
while($result = $stmt->fetch(PDO::FETCH_ASSOC)){ | |
$Field = $result['Field']; | |
$koumoku = $koumoku . "\t" . $Field; | |
} | |
echo $value . "\t" . $koumoku . "\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select TABLE_NAME, group_concat(COLUMN_NAME separator x'09') | |
from INFORMATION_SCHEMA.COLUMNS | |
where TABLE_NAME like 'S%' | |
group by TABLE_NAME | |
order by TABLE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-------------------+-------------------------------------------------- | |
| TABLE_NAME | group_concat(COLUMN_NAME separator x'09') | |
+-------------------+-------------------------------------------------- | |
| SCHEMATA | CATALOG_NAME SCHEMA_NAME | |
| SCHEMA_PRIVILEGES | IS_GRANTABLE PRIVILEGE_TYPE TABLE_SCHEMA | |
| SESSION_STATUS | VARIABLE_VALUE VARIABLE_NAME | |
| SESSION_VARIABLES | VARIABLE_NAME VARIABLE_VALUE | |
| STATISTICS | CARDINALITY SUB_PART PACKED NULLABLE | |
+-------------------+--------------------------------------------------- | |
5 rows in set (0.02 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment