SQL problems

Results 1 to 2 of 2

Thread: SQL problems

  1. #1
    Join Date
    Dec 1969

    Default SQL problems

    Imagine I have a table with the columns:<BR>PersonID (foreign key)<BR>EventID (foreign key)<BR>LeftEarly (boolean)<BR>EndDate (date)<BR><BR>The idea is that the SQL query returns the first date each person leaves each event(someone may attend the same event twice).<BR><BR>Easy enough, that bit I can do with the following Statement:<BR><BR>SELECT MIN(StartDate) FROM table GROUP BY PersonID, EventID<BR><BR>However, I also want to know whether the person left early. How can make the SQL return the value of LeftEarly that corresponds the EndDate I have returned.

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL problems

    Don&#039;t know if this is the best answer but..<BR>As far as I know you can&#039;t group on a bit(boolean) column so the workaround is to convert it - true is 1 and false is 0. Thus:<BR>SELECT MIN(StartDate),SUM(CONVERT(int,LeftEarly)) FROM table GROUP BY PersonID, EventID<BR>I think that&#039;s right, try it!<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts