הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   עזרה קטנה עם sql (https://hosts.co.il/forums/showthread.php?t=25630)

Smolf3d 04-07-06 16:55

עזרה קטנה עם sql
 
אז ככה,ביגלל שיש לי גירסת mysql 4.0 אז הפונקציה count לא עובדת,אני צריך לפצל ל-2 את הקוד כדי שיעבוד ...

PHP קוד:

select descr
     
image
     
, ( select count(*)
           
from users
          where groups 
groups.id ) as users_in_groups
     
, ( select count(*)
           
from torrents
          where grupa 
groups.id ) as users_in_torrents
  from groups


תודה למבינים ...

eLad 04-07-06 17:02

בספק אם mysql תומך בשאילתות מקוננות ..

בוא תנסה להסביר במילים מה בדיוק אתה מנסה לעשות (לשלוף) ואנסה לעזור

ואני דווקא חושב ש count כן נתמך.

Smolf3d 04-07-06 17:11

הוא ניתמך אבל אי אפשר לחבר 3 טבלאות לאחת ... אז ככה הסבר ...

יש לי 3 טבלאות

קוד:

      groups
+-------+-------+
| descr | image |
+-------+-------+

קוד:

  users
+--------+
| groups |
+--------+

קוד:

torrents
+-------+
| grupa |
+-------+

אני צריך לחבר את שלושתם,שיצא סטטיסטיקה

קוד:

+--------+-----------------------+-------------------+
| Groups |    Users in groups  |      Torrents    |
+--------+-----------------------+-------------------+
|  FunTV |          5          |          9        |
+--------+-----------------------+-------------------+
| M-Zone |          15          |          18      |
+--------+-----------------------+-------------------+
| Bt-Mov |          3          |          6        |
+--------+-----------------------+-------------------+

הצלחתי לעשות שהיא תעבוד על שרת ביתי (localhost) וכאשר בדקתי על השרת אז לא פועל ביגלל גירסת mysql ... אני צריך לחלק את השאלתת sql ל-2 .

PHP קוד:

select descr
     
image
     
, ( select count(*)
           
from users
          where groups 
groups.id ) as users_in_groups
     
, ( select count(*)
           
from torrents
          where grupa 
groups.id ) as users_in_torrents
  from groups



Smolf3d 04-07-06 17:18

לא חשוב,תודה רבה על הניסיון בעזרה,הצלחתי לעשות סוף סוף ... :-D

1.

PHP קוד:

select g.descr
     
g.image
     
count(users.groups) as users_in_groups
  from groups 
as g
left outer
  join users
    on users
.groups g.id 
group
    by g
.descr
     
g.image

2.

PHP קוד:

select g.descr
     
g.image
     
count(torrents.grupa) as users_in_torrents
  from groups 
as g
left outer
  join torrents
    on torrents
.grupa g.id 
group
    by g
.descr
     
g.image

אפשר לסגור/למחוק


כל הזמנים הם GMT +2. הזמן כעת הוא 08:35.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ