??? SQL-Stament für Woche ???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ??? SQL-Stament für Woche ???

    Gib es ein Aufruf in SQL für Woche (mo- so(de) || so - sa(us))?

    Ich möchte mir immer nur die Letzte Woche ausgeben lassen.
    Beginnent bei Montag.
    *winks*
    Gilbert
    ------------------------------------------------
    Hilfe für eine Vielzahl von Problemen!!!
    http://www.1st-rootserver.de/

  • #2
    schau Dir das an
    DATE_FORMAT(date,format)
    Beantworte nie Threads mit mehr als 15 followups...
    Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

    Comment


    • #3
      DATE_FORMAT kenn ich aber wie kann ich das auf die Wochen anwenden.

      Code:
      SELECT DATE_FORMAT(datum,"d%.m%.Y%") FROM tabelle
      *winks*
      Gilbert
      ------------------------------------------------
      Hilfe für eine Vielzahl von Problemen!!!
      http://www.1st-rootserver.de/

      Comment


      • #4
        MYSQL.ORG

        WEEKDAY(datum)
        Gibt den Wochentag-Index für datum zurück (0 = Montag, 1 = Dienstag, ... 6 = Sonntag):
        mysql> select WEEKDAY('1997-10-04 22:23:00');
        -> 5
        mysql> select WEEKDAY('1997-11-05');
        -> 2
        Wie kann ich das jetzt umsetzen. Beziehungsweise wie muss ich das jetzt einbauen. Wenn ich ein Ergebnis aus COUNT(art_id) für diese Woche 2003-03-17 14:00:00 haben will.
        *winks*
        Gilbert
        ------------------------------------------------
        Hilfe für eine Vielzahl von Problemen!!!
        http://www.1st-rootserver.de/

        Comment


        • #5
          Original geschrieben von Wotan
          DATE_FORMAT kenn ich aber wie kann ich das auf die Wochen anwenden.

          Code:
          SELECT DATE_FORMAT(datum,"d%.m%.Y%") FROM tabelle
          Scheinbar nicht:

          %U Week (0..53), where Sunday is the first day of the week
          %u Week (0..53), where Monday is the first day of the week
          Hatte mich aber auch vetan denn:

          WEEK(date,first)
          With a single argument, returns the week for date, in the range 0 to 53 (yes, there may be the beginnings of a week 53), for locations where Sunday is the first day of the week. The two-argument form of WEEK() allows you to specify whether the week starts on Sunday or Monday. The week starts on Sunday if the second argument is 0, on Monday if the second argument is 1:
          Beantworte nie Threads mit mehr als 15 followups...
          Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

          Comment


          • #6
            EDIT:

            So muss es sein.
            Code:
            SELECT COUNT(art_id) AS tag, WEEK(NOW(),1) AS woche FROM tabelle GROUP BY art_id


            Last edited by Wotan; 18-03-2003, 13:54.
            *winks*
            Gilbert
            ------------------------------------------------
            Hilfe für eine Vielzahl von Problemen!!!
            http://www.1st-rootserver.de/

            Comment


            • #7
              Schon im Ansatz allerdings musst Du eine gruppierung vornehmen...
              Beantworte nie Threads mit mehr als 15 followups...
              Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

              Comment


              • #8
                Wie kann ich das jetzt erweitern auf eine Woche vorher und zwei Wochen vorher vor heute?
                *winks*
                Gilbert
                ------------------------------------------------
                Hilfe für eine Vielzahl von Problemen!!!
                http://www.1st-rootserver.de/

                Comment


                • #9
                  Also es muss so sein:
                  SELECT COUNT(art_id) AS tag, WEEK(datumsfeld,1) AS woche FROM tabelle GROUP BY WEEK(datumsfeld,1);

                  Letzte Woche:
                  SELECT COUNT(art_id) AS tag, WEEK(NOW(),1) AS woche FROM tabelle
                  WHERE WEEK(datumsfeld,1) = WEEK(NOW(),1)-1
                  GROUP BY WEEK(NOW(),1);

                  allerdings musst Du noch das Jahr mit einbauen...
                  (YEAR())
                  Beantworte nie Threads mit mehr als 15 followups...
                  Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

                  Comment


                  • #10
                    PHP Code:
                    <?
                    // " Wochen zurück
                    $r5_2 = mysql_query("SELECT COUNT(art_id) AS tag, WEEK(NOW(),1) AS woche2 FROM werben WHERE WEEK(wann,1)=WEEK(NOW(),1)-2 GROUP BY art_id")or die("FEHLER: ".mysql_error());
                    while($ro5_2 = mysql_fetch_array($r5_2))
                    {
                    echo "<tr><td><font face=\"Verdana\" size=\"1\">Vorletzte Woche => $ro5_2[woche2] Besucher</font></td></tr>";
                    }
                    // Eine Woche Zurück
                    $r5_1 = mysql_query("SELECT COUNT(art_id) AS tag, WEEK(NOW(),1) AS woche1 FROM werben WHERE WEEK(wann,1)=WEEK(NOW(),1)-1 GROUP BY art_id")or die("FEHLER: ".mysql_error());
                    while($ro5_1 = mysql_fetch_array($r5_1))
                    {
                    echo "<tr><td><font face=\"Verdana\" size=\"1\">Letzte Woche => $ro5_1[woche1] Besucher</font></td></tr>";
                    }
                    // Diese Woche
                    $r5 = mysql_query("SELECT COUNT(art_id) AS tag, WEEK(NOW(),1) AS woche FROM werben GROUP BY art_id")or die("FEHLER: ".mysql_error());
                    while($ro5 = mysql_fetch_array($r5))
                    {
                    echo "<tr><td><font face=\"Verdana\" size=\"1\">aktuelle Woche => $ro5[woche] Besucher</font></td></tr>";
                    }
                    ?>
                    Allerding schein da was nicht zu stimmen:
                    12.03.03 => 4 Besucher
                    13.03.03 => 6 Besucher
                    14.03.03 => 6 Besucher
                    15.03.03 => 8 Besucher
                    16.03.03 => 17 Besucher
                    17.03.03 => 8 Besucher
                    18.03.03 => 4 Besucher
                    Besucher Gesamt
                    Gesamt => 53 Besucher
                    Besucher pro Woche
                    Letzte Woche => 12 Besucher
                    aktuelle Woche => 12 Besucher
                    *winks*
                    Gilbert
                    ------------------------------------------------
                    Hilfe für eine Vielzahl von Problemen!!!
                    http://www.1st-rootserver.de/

                    Comment


                    • #11
                      Du gruppierst falsch.
                      Du musst nach wochen gruppieren...
                      Oder Deine query muss anders aussehen...
                      Beantworte nie Threads mit mehr als 15 followups...
                      Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

                      Comment


                      • #12
                        Ändert sich nicht.
                        Bleibt dabei das in der letzten Woche 12
                        und diese Woche auch 12 dawaren.
                        *winks*
                        Gilbert
                        ------------------------------------------------
                        Hilfe für eine Vielzahl von Problemen!!!
                        http://www.1st-rootserver.de/

                        Comment


                        • #13
                          Ja weil Du immer week(now()) nimmst du musst sowas nehmen:

                          mysql_query("

                          SELECT WEEK(datums_feld,1), YEAR(datums_feld), COUNT(art_id)
                          FROM werben
                          GROUP BY WEEK(datums_feld,1) ,YEAR(datums_feld)

                          ")or die("FEHLER: ".mysql_error());
                          Beantworte nie Threads mit mehr als 15 followups...
                          Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

                          Comment


                          • #14
                            Original geschrieben von MelloPie
                            Ja weil Du immer week(now()) nimmst du musst sowas nehmen:

                            mysql_query("

                            SELECT WEEK(datums_feld,1), YEAR(datums_feld), COUNT(art_id)
                            FROM werben
                            GROUP BY WEEK(datums_feld,1) ,YEAR(datums_feld)

                            ")or die("FEHLER: ".mysql_error());
                            Meine Query Sieht jetzt so aus:
                            PHP Code:
                            mysql_query("SELECT COUNT(art_id) AS tag, 
                            WEEK(wann,1) AS woche1 
                            FROM werben 
                            WHERE WEEK(wann,1)=WEEK(NOW(),1)-1 
                            GROUP BY WEEK(wann,1)"
                            )or die("FEHLER: ".mysql_error()); 
                            Und auch das ändert nicht daran.

                            Das Ergenbnis ist immer noch:
                            Besucher pro Woche
                            Letzte Woche => 11 Besucher
                            aktuelle Woche => 12 Besucher
                            *winks*
                            Gilbert
                            ------------------------------------------------
                            Hilfe für eine Vielzahl von Problemen!!!
                            http://www.1st-rootserver.de/

                            Comment


                            • #15
                              Meiner Fehler!!!
                              Anstatt die Besucher(tag) aus zugeben, habe ich mir die KW(woche) ausgeben lassen und die ist nun mal momentan 11&12.
                              *winks*
                              Gilbert
                              ------------------------------------------------
                              Hilfe für eine Vielzahl von Problemen!!!
                              http://www.1st-rootserver.de/

                              Comment

                              Working...
                              X