473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

transpose result of query from mysql

I need of result below in different way

Thanks any help!

QUERY:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. t.`trafego_data`,
  3. u.`uf_sigla`,
  4. sum(t.`trafego_qtd`) as trafego_qtd
  5.  
  6. FROM
  7. trafego t INNER JOIN uf_ddd u ON t.`uf_ddd_cod` = u.`uf_ddd_cod`
  8. WHERE
  9. t.`trafego_data` BETWEEN '20070801' AND '20070803' AND
  10. t.`trafego_skill` = 'VENDAS SAC'
  11. GROUP BY t.`trafego_data`,u.`uf_sigla`
  12. ORDER BY t.`trafego_data`,u.`uf_sigla`, trafego_qtd
RETURN OF QUERY
Expand|Select|Wrap|Line Numbers
  1. trafego_data    uf_sigla    trafego_qtd
  2. 1/8/2007    AC    6
  3. 1/8/2007    AL    1
  4. 1/8/2007    BA    4
  5. 1/8/2007    CE    2
  6. 1/8/2007    DF    3
  7. 1/8/2007    ES    1
  8. 1/8/2007    GO    1506
  9. 1/8/2007    MA    2
  10. 1/8/2007    MG    29
  11. 1/8/2007    MT    788
  12. 1/8/2007    NI    404
  13. 1/8/2007    PA    11
  14. 1/8/2007    PE    9
  15. 1/8/2007    PI    1
  16. 1/8/2007    PR    3482
  17. 1/8/2007    RJ    21
  18. 1/8/2007    RN    1
  19. 1/8/2007    RO    30
  20. 1/8/2007    RS    3022
  21. 1/8/2007    SC    1864
  22. 1/8/2007    SP    34
  23. 1/8/2007    TO    295
  24. 2/8/2007    AC    4
  25. 2/8/2007    AL    1
  26. 2/8/2007    AM    1
  27. 2/8/2007    AP    1
  28. 2/8/2007    BA    5
  29. 2/8/2007    CE    3
  30. 2/8/2007    DF    6
  31. 2/8/2007    ES    2
  32. 2/8/2007    GO    1490
  33. 2/8/2007    MA    3
  34. 2/8/2007    MG    17
  35. 2/8/2007    MS    5
  36. 2/8/2007    MT    688
  37. 2/8/2007    NI    351
  38. 2/8/2007    PA    6
  39. 2/8/2007    PE    3
  40. 2/8/2007    PR    3241
  41. 2/8/2007    RJ    26
  42. 2/8/2007    RN    3
  43. 2/8/2007    RO    15
  44. 2/8/2007    RS    2672
  45. 2/8/2007    SC    1518
  46. 2/8/2007    SP    48
  47. 2/8/2007    TO    239
  48. 3/8/2007    AC    8
  49. 3/8/2007    AL    7
  50. 3/8/2007    AM    7
  51. 3/8/2007    AP    1
  52. 3/8/2007    BA    4
  53. 3/8/2007    CE    1
  54. 3/8/2007    DF    4
  55. 3/8/2007    ES    2
  56. 3/8/2007    GO    1107
  57. 3/8/2007    MA    7
  58. 3/8/2007    MG    20
  59. 3/8/2007    MS    6
  60. 3/8/2007    MT    694
  61. 3/8/2007    NI    284
  62. 3/8/2007    PA    7
  63. 3/8/2007    PB    1
  64. 3/8/2007    PE    3
  65. 3/8/2007    PI    1
  66. 3/8/2007    PR    2452
  67. 3/8/2007    RJ    13
  68. 3/8/2007    RO    31
  69. 3/8/2007    RS    2338
  70. 3/8/2007    SC    1226
  71. 3/8/2007    SP    38
  72. 3/8/2007    TO    208
I NEED THE RETURN LIKE THAT:
Expand|Select|Wrap|Line Numbers
  1. DIA        AC   DF   GO   ..., 
  2. 1/8/2007   6    3    1506
  3. 2/8/2007   4    6    1490
  4. 3/8/2007   8    4    1107
THANKS ANY HELP!
Aug 9 '07 #1
1 4968
pbmods
5,821 Expert 4TB
Heya, Daniel. Welcome to TSDN!

MySQL really won't be able to give you exactly what you want there.

You have three options:
  • You can run a separate query for each day and then parse the results in a separate script (e.g., PHP).
  • You can use what you're currently getting and do all of the calculations in a separate script (e.g., PHP).
  • You can create a stored procedure to create a table with one column for each distinct value of `uf_sigla`, and then run a query for each `uf_sigla` and populate each column of the table. If it absolutely has to be done in MySQL, then this is the way you'd have to do it *HOWEVER* note that this is probably the slowest way, performance-wise, to do it!
Aug 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Noel Wood | last post by:
Hello I keep getting a warning ... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in "name of my php file" when I run this query.... SELECT Menu_Item,...
13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
0
by: Doug Reese | last post by:
hello, i have what seems to me a very common operation i'm performing. i need to find the balance on an invoice. i was not having any problems until the production server was upgraded to mysql...
4
by: Bob Bedford | last post by:
We have no access to a mysql NG on my provider's server, so we ask here: We have a long query (long in text) with a UNION between 2 select. We have been informed that some times the query...
1
by: jenny.rhodes | last post by:
Hello, Please can anyone guide me on how to transpose an access table where I have many records per id eg UserID Question Answer 1 1 a 1 2 d 1 3 ...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
6
by: JayDawg | last post by:
Excel has this cool little function where you can copy data, and then paste it transposed so that which runs across the rows now runs down a colum and visa versa. Is there a way in access to...
1
by: automation | last post by:
There is a truncation error of my Web Application using PHP 5.04, MySQL 5.022, and HTML(IE 6.0) whereby the MySQL Result Set is being truncated on the HTML page, even though the CSS Div Page Height...
2
by: east7 | last post by:
Hi all, I am using SQL 2000, and I have following table with 2 columns, ID and TIME ID | TIME A | 07:01 A | 12:05 A | 13:01 A | 15:09 B | 15:07
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.