Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z zapytaniem
Ryder
post 17.11.2011, 16:53:12
Post #1





Grupa: Zarejestrowani
Postów: 74
Pomógł: 1
Dołączył: 5.01.2008

Ostrzeżenie: (0%)
-----


Witam

Tabela



Potrzebuje napisać takie zapytanie, które zwróci mi ilość testów (test_id) wykonanych w danym dniu dla danego projektu (projekt_id)
Czyli zwróci tabelę jak poniżej (wartości w tabeli przypadkowe)

Status b Status p Status f Łącznie
2011-11-08 | 2 | 3 | 1 | 7
2011-11-09 | 1 | 2 | 1 | 4
2011-11-10 | 1 | 1 | 0 | 2
2011-11-11 | 5 | 4 | 10 | 19


Prośba o pomoc w napisaniu zapytania. Czy da się to zrobić 1 zapytaniem?

Próbowałem na początek pogrupować dane.

  1. SELECT id,execution_date, STATUS, project_id, test_id, platform_id FROM executions GROUP BY project_id, platform_id, execution_date, STATUS HAVING project_id = '3347' ORDER BY id DESC



Należy zwrócić uwagę, że

(1) Podane poniżej trzy wpisy należy traktować jako 1 test, ponieważ jest ta sama wartość platform_id.

Test_id (1544) o platformie (159) przyjmuje status (f), najbardziej aktualny po dacie wykonania
I tylko ten jest zliczany do tabeli docelowej

id data_wykonania status projekt_id test_id platform_id
1753 2011-11-14 14:13:31 f 3347 1544 159
1750 2011-11-14 14:12:35 b 3347 1544 159
1745 2011-11-14 14:10:43 p 3347 1544 159


(2) Natomiast jeżeli te wpisy mają różną platformę to są to 3 różne wpisy i trzeba j traktować jako 3 różne testy
W tym przypadku dla dnia 2011-11-14 trzeba policzyć każdy z wpisów.

id data_wykonania status projekt_id test_id platform_id
1753 2011-11-14 14:13:31 f 3347 1544 157
1750 2011-11-14 14:12:35 b 3347 1544 158
1745 2011-11-14 14:10:43 p 3347 1544 159

Ten post edytował Ryder 17.11.2011, 19:17:15
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
melkorm
post 17.11.2011, 17:26:05
Post #2





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Podaj strukturę tabeli + przykładowe dane (jako SQL).


--------------------
Go to the top of the page
+Quote Post
Ryder
post 17.11.2011, 19:12:10
Post #3





Grupa: Zarejestrowani
Postów: 74
Pomógł: 1
Dołączył: 5.01.2008

Ostrzeżenie: (0%)
-----


  1. CREATE TABLE IF NOT EXISTS executions (
  2. id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  3. build_id int(10) NOT NULL DEFAULT 0,
  4. tester_id int(10) UNSIGNED DEFAULT NULL,
  5. execution_date datetime DEFAULT NULL,
  6. STATUS char(1) DEFAULT NULL,
  7. project_id int(10) UNSIGNED NOT NULL DEFAULT 0,
  8. test_id int(10) UNSIGNED NOT NULL DEFAULT 0,
  9. platform_id int(10) UNSIGNED NOT NULL DEFAULT 0,
  10. PRIMARY KEY (id)
  11. );


  1. INSERT INTO executions (id, build_id, tester_id, execution_date, STATUS, project_id, test_id, platform_id) VALUES
  2. (1753, 36, 8, '2011-11-14 14:13:31', 'f', 3347, 1544, 159),
  3. (1750, 36, 7, '2011-11-14 14:12:35', 'b', 3347, 1544, 159),
  4. (1745, 36, 8, '2011-11-14 14:10:43', 'p', 3347, 1544, 159),
  5. (1752, 36, 7, '2011-11-14 14:12:51', 'p', 3347, 1547, 159),
  6. (1746, 36, 8, '2011-11-14 14:10:51', 'f', 3347, 1547, 159),
  7. (1747, 36, 8, '2011-11-14 14:12:12', 'p', 3347, 1550, 159),
  8. (1748, 36, 8, '2011-11-14 14:12:26', 'p', 3347, 1553, 159),
  9. (1751, 36, 8, '2011-11-14 14:12:43', 'p', 3347, 1556, 159),
  10. (1749, 36, 8, '2011-11-14 14:12:33', 'f', 3347, 1556, 159),
  11. (1699, 36, 7, '2011-11-09 11:06:07', 'p', 3347, 1897, 136),
  12. (1701, 36, 7, '2011-11-09 11:06:45', 'p', 3347, 1897, 137),
  13. (1713, 36, 7, '2011-11-09 12:23:48', 'p', 3347, 1897, 152),
  14. (1720, 36, 7, '2011-11-09 12:24:55', 'p', 3347, 1897, 153),
  15. (1721, 36, 7, '2011-11-09 12:25:00', 'p', 3347, 1897, 153),
  16. (1722, 36, 7, '2011-11-09 12:25:05', 'p', 3347, 1897, 153),
  17. (1707, 36, 7, '2011-11-09 12:22:01', 'i', 3347, 1901, 137),
  18. (1714, 36, 7, '2011-11-09 12:23:56', 'p', 3347, 1901, 152),
  19. (1723, 36, 7, '2011-11-08 12:25:14', 'p', 3347, 1901, 153),
  20. (1708, 36, 7, '2011-11-09 12:22:06', 'b', 3347, 1904, 137),
  21. (1715, 36, 7, '2011-11-09 12:24:04', 'p', 3347, 1904, 152),
  22. (1724, 36, 7, '2011-11-08 12:25:21', 'p', 3347, 1904, 153),
  23. (1709, 36, 7, '2011-11-09 12:22:10', 'p', 3347, 1907, 137),
  24. (1716, 36, 7, '2011-11-09 12:24:12', 'p', 3347, 1907, 152),
  25. (1725, 36, 7, '2011-11-08 12:25:30', 'p', 3347, 1907, 153),
  26. (1710, 36, 7, '2011-11-09 12:22:16', 'f', 3347, 1910, 137),
  27. (1717, 36, 7, '2011-11-09 12:24:20', 'p', 3347, 1910, 152),
  28. (1726, 36, 7, '2011-11-08 12:25:47', 'p', 3347, 1910, 153),
  29. (1711, 36, 7, '2011-11-09 12:22:23', 'p', 3347, 1913, 137),
  30. (1718, 36, 7, '2011-11-09 12:24:25', 'p', 3347, 1913, 152)



Chciłbym zwrócić zapytaniem tabelę [Dzień - ilość]

--Dzień--------Status:s---------Status:p------ Status:b------Razem
2011-11-14--------1----------------2--------------1------------4
2011-11-09--------5----------------7--------------3------------15
2011-11-08--------4----------------1--------------3------------8
Wartości przykładowe


Częściowo udaje mi się wydobyć dane zapytaniem, ale nie do końca jet to to co chce.
  1. SELECT execution_date, STATUS, count(*) AS quantity FROM (SELECT * FROM (SELECT id,DATE_FORMAT(execution_date,GET_FORMAT(DATE,'ISO')) AS 'execution_date', STATUS, project_id, test_id, platform_id FROM (SELECT id,execution_date, STATUS, project_id, test_id, platform_id FROM executions GROUP BY project_id, platform_id, execution_date, STATUS HAVING project_id = '3347' ORDER BY test_id ASC) AS temp GROUP BY execution_date, test_id, platform_id) AS temp2 GROUP BY execution_date, test_id, platform_id) AS Temp3 GROUP BY execution_date, STATUS



Ten post edytował Ryder 17.11.2011, 19:46:29
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 02:21