0

49I need help understanding the approach to take with a problem. I have a data base that contains the fields id, LastUpdate, member_name, member_extension (phone ext), member_account_id, queue_account_id.

| id | LastUpdate  | member_name | member_extension | member_account_id | queue_account_id |
-------------------------------------------------------------------------------------------
| 1  | 2013-10-15  | John Smith  | 2750             | 1195              | 1105             |
| 2  | 2013-10-15  | Bill Jones  | 2749             | 1172              | 1248             |
| 3  | 2013-10-15  | Bill Jones  | 2749             | 1172              | 1105             |
| 4  | 2013-10-15  | Fred Black  | 2745             | 1195              | 1105             |
-------------------------------------------------------------------------------------------

My problem is I need to show in a table the member_account_id's of each member in a queue. For instance queue_account_id 1105 has member_extensions 2450, 2741 & 2745 listed, I need to show those extensions in a table cell. I'm using php and mysql to access database. How do I approach this?

EDIT: Here is the table I need to display, I have all of it working except the techs logged in part. i guess my main problem is understanding how to get the queried tech identity data into the techs logged in field.

| Queue    | Calls | % total calls  | answered by us| % answered by us| abandoned | % abandoned | Redirected | % Redirected | Techs Logged In |   
----------------------------------------------------------------------------------------------------------------------------------------------|
| Premium  | 1     | 9%             | 0             | 0%              | 1         | 100%        | 0          | 0%           |                 |
| Standard | 2     | 0%             | 1             | 150%            | 0         | 0%          | 1          | 50%          |                 | 
| Queue 2  | 1     | 0%             | 1             | 100%            | 0         | 0%          | 0          | 0%           |                 | 
| Queue 3  | 7     | 64%            | 4             | 57%             | 3         | 43%         | 1          | 0%           |                 |                  
| Totals   | 11    | 100%           | 6             | 55%             | 4         | 36%         | 1          | 9%           |                 |                  
----------------------------------------------------------------------------------------------------------------------------------------------|
4

4 に答える 4

1
SELECT
t1.queue_account_id, GROUP_CONCAT(DISTINCT t2.member_extension) member_extensions
FROM tblname t1
INNER JOIN tblname  t2 USING (queue_account_id)
GROUP BY t1.queue_account_id

これは、シナリオでそれを提示する方法です。

<?php

$link = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('dbname');

$sql = 'SELECT
    t1.queue_account_id, GROUP_CONCAT(DISTINCT t2.member_extension) member_extensions
    FROM tblname t1
    INNER JOIN tblname t2 USING (queue_account_id)
    GROUP BY t1.queue_account_id';
$query = mysql_query($sql) or die(mysql_error());

echo '<table border="1">';

while ($rs = mysql_fetch_object($query)) {
echo '<tr>';
echo '<td>' . $rs->queue_account_id . '</td>';
echo '<td>';
echo '<ul>';
foreach (explode(',', $rs->member_extensions) as $extension) {
    echo '<li>' . $extension . '</li>';
}
echo '</ul>';
echo '</td>';
echo '</tr>';
}

echo '</table>';
于 2013-10-23T13:31:43.020 に答える
1

これを探していますか?

SELECT queue_account_id, 
       GROUP_CONCAT(member_extension) member_extension
  FROM table1
 GROUP BY queue_account_id

出力:

| | QUEUE_ACCOUNT_ID | MEMBER_EXTENSION |
|------------------|------------------|
| | 1105 | 2750,2741,2745 |
| | 1248 | 2749 |

これがSQLFiddleのデモです

于 2013-10-23T13:32:50.247 に答える