Jump to content

fenway

Staff Alumni
  • Posts

    16,168
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by fenway

  1. Duplicate should be referring to individual field values, not parts of a field -- storing delimited data that you need to consider separately is likely going to bite you soon enough, if it hasn't already.

     

    There's all sorts of tomfoolery you can do with FIND_IN_SET(), but I don't recommend it.

  2. This is screaming for normalization, but this will work (link to http://sqlfiddle.com/#!2/30c2b/1/0):

    select id
    , IFNULL(group_concat(year1),0) as `Year 1`
    , IFNULL(group_concat(year2),0) as `Year 2`
    , IFNULL(group_concat(year3),0) as `Year 3`
    from (
    select id
    , IF(year1,score,null) as year1
    , IF(year2,score,null) as year2
    , IF(year3,score,null) as year3
    from scores
    ) t1
    group by id;

    Obviously, depending on how you want duplicates and sorting, you'll need to tweak the group_concat() call slightly.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.