Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyświetlanie policzonych
Zen Vantalye
post 12.01.2008, 07:22:10
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 1
Dołączył: 29.09.2007

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


Czy istnieje możliwość żeby jak mam tablice zawierającą pole id i name a zawartość np.
id name
1 1
2 2
3 3
4 3
5 4
6 2
7 5
8 3
Wyswietlić jednym zapytaniem posortowane według ilości powtórzeń name czyli
id name ile
3 3 3
4 3 3
8 3 3
6 2 2
2 2 2
5 4 1
7 5 1
1 1 1
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
batman
post 12.01.2008, 12:10:13
Post #2





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




  1. SELECT id, name, count(name) AS ilosc FROM tabela GROUP BY name ORDER BY ilosc DESC


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
nevt
post 12.01.2008, 13:46:30
Post #3





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


wg mnie, to co kolega Zen chce osiągnąć nie jest takie proste...
  1. SELECT * FROM tabela LEFT JOIN (SELECT name , COUNT(name) AS ile FROM tabela GROUP BY name) AS tmp
  2. USING(name) ORDER BY ile DESC, id;


Ten post edytował nevt 12.01.2008, 13:47:53


--------------------

-
Oh no, my young coder. You will find that it is you who are mistaken, about a great many things... -
Go to the top of the page
+Quote Post
Zen Vantalye
post 12.01.2008, 20:24:06
Post #4





Grupa: Zarejestrowani
Postów: 13
Pomógł: 1
Dołączył: 29.09.2007

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


batman:Dziękuje za zapytanie dzięki któremu udało mi się stworzyć chmurkę tagów chociaż faktycznie nie o to mi chodziło.
nevt:Niestety ale te zapytanie mi nie działa i niemoge sobie poradzić z naprawieniem go ale mimo tego dziękuje za chęci.

Problem rozwiązałem.
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: 26.06.2025 - 03:07