SQL request, withdrawal of date and date



  • That's the job. So there's a table with dates. (TABLE dates):

    id |    date
    ---+-------------
     1 |'2011-01-01'
     2 |'2011-01-02'
     3 |'2011-01-03'
    ...
    31 |'2011-01-31'
    

    There is also a schedule of work. (TABLE grafik):

    id | den_ned | NAME
    ---+---------+------
     1 |   Sat   | John
     2 |   Sat   | Clair
     3 |   Mon   | Cliff
     4 |   Mon   | Tom
     5 |   Mon   | Linda
     6 |   Tue   | Neo
    ...
     ? |   Sun   | Alex
    

    For example, it is said that on Saturdays, we have to go to work. John and ClairMonday- CliffTom and Lindaon Sunday -- Alex etc.

    We need to make a request to get him out of dates. About:

    id |    date    | NAME
    ---+------------+-----
     1 |'2011-01-01'| John
     2 |'2011-01-01'| Clair
     3 |'2011-01-02'| Cliff
     4 |'2011-01-02'| Tom
     5 |'2011-01-02'| Linda
     6 |'2011-01-03'| Neo
    ...
     ? |'2011-01-31'| Linda
    

    So, 2011-01-01 Saturday, there are two records. id=1,2) Next, 2011-01-02 3 records (c) id=3,4,5etc.



  • For the muscle, I did it like that:

    SELECT d.date, g.NAME
    FROM  `grafik` AS g, `dates` AS d
    WHERE g.den_ned = SUBSTRING( DATE_FORMAT( d.date,  '%W' ) , 1, 3 )
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2