Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pomoc z utworzeniem odpowiedniego SELECT
saren_as
post
Post #1





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 21.07.2008

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


Witam.
Mam takie tabele:

  1. CREATE TABLE `vservers_status` (
  2. `vserver_ip` varchar(15) NOT NULL DEFAULT '',
  3. `filer_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
  4. `node_id` int(10) UNSIGNED DEFAULT NULL,
  5. `started` tinyint(1) NOT NULL DEFAULT '0',
  6. `cpu_parts` int(10) UNSIGNED NOT NULL DEFAULT '0',
  7. `cpu_usage` int(10) UNSIGNED NOT NULL DEFAULT '0',
  8. `mem_size` int(10) UNSIGNED DEFAULT NULL,
  9. `mem_usage` int(10) UNSIGNED NOT NULL DEFAULT '0',
  10. `disk_size` int(10) UNSIGNED DEFAULT NULL,
  11. `disk_usage` int(10) UNSIGNED NOT NULL DEFAULT '0',
  12. `net_usage` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  13. `_net_last` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  14. `mem_usage_as` int(10) UNSIGNED NOT NULL DEFAULT '0',
  15. `mem_size_as` int(10) UNSIGNED NOT NULL DEFAULT '0',
  16. `net_usage_down` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  17. `_net_last_down` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  18. `net_usage_up` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  19. `_net_last_up` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  20. `date_created` datetime DEFAULT NULL,
  21. `last_modified` timestamp(14) NOT NULL,
  22. PRIMARY KEY (`vserver_ip`),
  23. UNIQUE KEY `index01` (`vserver_ip`)
  24. ) TYPE=InnoDB;

i

  1. CREATE TABLE `filers` (
  2. `filer_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  3. `mount_point` varchar(255) NOT NULL DEFAULT '',
  4. `hostname` varchar(50) NOT NULL DEFAULT '',
  5. `production` tinyint(1) NOT NULL DEFAULT '0',
  6. `running` tinyint(1) NOT NULL DEFAULT '0',
  7. `fs_size` int(10) UNSIGNED NOT NULL DEFAULT '0',
  8. `fs_usage` int(10) UNSIGNED NOT NULL DEFAULT '0',
  9. `mem_size` int(10) UNSIGNED DEFAULT NULL,
  10. `mem_usage` int(10) UNSIGNED DEFAULT NULL,
  11. PRIMARY KEY (`filer_id`)
  12. ) TYPE=MyISAM;


Jak zbudowac SELECT, aby wyswietlilo mi
vserwer_ip z filer_id o wartosciach >= 5
+
ilosc wolnego miejsca na filer_id o wartosci 1 (czyli: fs_size - fs_usage WHERE filer_id = 1)

Da rade to zrobic w jednym selekcie czy musze to zbudowac jako dwie zmienne?

Dzieki za rady i przepraszam za brak polskich znakow, ale nie mam polskiej klawiatury!
Pozdrawiam!
saren_as

Ten post edytował batman 15.09.2008, 10:05:57
Powód edycji: poprawiłem bbcode ~batman
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
Harmider
post
Post #2





Grupa: Zarejestrowani
Postów: 5
Pomógł: 2
Dołączył: 1.02.2007

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


Może tak:

  1. SELECT `vserver_ip` , (
  2. `fs_size` - `fs_usage`
  3. ) AS `fs_left`
  4. FROM `vservers_status` AS `v`
  5. LEFT JOIN `filers` AS `f` ON `f`.`filer_id` =1
  6. WHERE `v`.`filer_id` >=5;


Daj znać czy podziała, nie chce mi się sprawdzać ;)
Go to the top of the page
+Quote Post
saren_as
post
Post #3





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 21.07.2008

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


Dzieki za odpowiedz, a odpowiadam dopiero teraz bo nie mialem przez weekend dostepu do netu.
Zbudowany przez Ciebie select dziala i widze, ze czeka mnie jeszcze sporo roboty w nauce. Mam teraz jeszcze jedno zadanie, z ktorym nie moge sobie poradzic.

Dodatkowa tabela jak bedzie potrzebna to:

  1. CREATE TABLE `vroots` (
  2. `vid` varchar(15) NOT NULL DEFAULT '',
  3. `filer` varchar(100) NOT NULL DEFAULT '',
  4. `xid` int(10) UNSIGNED DEFAULT NULL,
  5. `existing` tinyint(1) NOT NULL DEFAULT '0',
  6. `count_idx` int(10) UNSIGNED NOT NULL DEFAULT '0',
  7. `dist` varchar(100) DEFAULT NULL,
  8. `dist_ver` int(11) DEFAULT NULL,
  9. PRIMARY KEY (`vid`,`filer`),
  10. UNIQUE KEY `index02` (`xid`,`filer`),
  11. KEY `index01` (`vid`,`filer`,`existing`)
  12. ) TYPE=MyISAM;



Chcial bym teraz zbudowac takie zapytanie, ktore wyswietli mi
wszystkie vservers_status.vserver_ip spelniajace jednoczesnie warunki
- MAX(fs_usage) FROM filers - czyli w tabeli filers odpowiadaja tylko wartoscia
z najwiekszym polem fs_usage
- vroots.existing = '1';

Musze zatem pobrac dane z trzech tabel i ograniczyc je dwoma warunkami.
Da ktos rade to zrobic?

Jezeli sie zle wyslowilem to podam teraz moje zapytania, ale w oddzielnych SELECT:

  1. SELECT MAX(fs_usage)
  2. FROM filers;


  1. SELECT vserver_ip FROM vservers_status JOIN vroots ON vservers_status.vserver_ip = vroots.vid
  2. WHERE vroots.existing = '1';

Jak polaczyc to teraz w jedno zapytanie?
Pozdrawiam i dzieki za pomoc ! ! !

Ten post edytował batman 15.09.2008, 10:06:58
Powód edycji: poprawiłem bbcode ~batman
Go to the top of the page
+Quote Post
batman
post
Post #4





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




@saren_as Zacznij używać bbcode.


--------------------
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

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 Aktualny czas: 20.08.2025 - 08:31