Question : Union select and grouping

I have three select statements that return a value of any test a person has failed for 2008,2009, and 2010. I want it to return only the people that have failed 2 times over the three years. Doesn't have to be the same test, but any two tests. Also I need for them to be on the same row.  Thanks

Results wanted
emplid  2008   2009   2010
123      math                 eng
234       eng      ss
345      eng       ss        math

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
/* Formatted on 7/15/2010 1:26:35 PM (QP5 v5.139.911.3011) */
  SELECT *
    FROM (  SELECT b.hub_cd,
                   RTRIM (
                      EXTRACT (
                         XMLAGG (XMLELEMENT ("s", d.tsa08_tp_subtype || ',')),
                         '/s/text()').getstringval (),
                      ',')
                      AS "2008",
                   ' ' AS "2009",
                   ' ' AS "2010",
                   c.emplid
              FROM pemployees a,
                   airport_tbl b,
                   pass c,
                   dnm08_vw d
             WHERE     c.emplid = a.emplid
                   AND c.emplid = d.emplid
                   AND b.tsa_airport_cd = c.tsa_airport_cd
                   AND c.tsa10_status <> 'P'
                   AND b.effdt = (SELECT MAX (effdt)
                                    FROM ps_tsa_airport_tbl
                                   WHERE tsa_airport_cd = b.tsa_airport_cd)
          GROUP BY hub_cd, c.emplid
          UNION
            SELECT hub_cd,
                   ' ' AS "2008",
                   RTRIM (
                      EXTRACT (
                         XMLAGG (XMLELEMENT ("s", e.tsa09_tp_subtype || ',')),
                         '/s/text()').getstringval (),
                      ',')
                      AS "2009",
                   ' ' AS "2010",
                   c.emplid
              FROM employees a,
                   airport_tbl b,
                   pass c,
                   ps_tsa10_dnm09_vw e
             WHERE     c.emplid = a.emplid
                   AND c.emplid = e.emplid
                   AND b.tsa_airport_cd = c.tsa_airport_cd
                   AND c.tsa10_status <> 'P'
                   AND b.effdt = (SELECT MAX (effdt)
                                    FROM ps_tsa_airport_tbl
                                   WHERE tsa_airport_cd = b.tsa_airport_cd)
          GROUP BY hub_cd, c.emplid
          UNION
            SELECT hub_cd,
                   '' AS "2008",
                   ' ' AS "2009",
                   RTRIM (
                      EXTRACT (
                         XMLAGG (XMLELEMENT ("s", f.tsa10_tp_subtype || ',')),
                         '/s/text()').getstringval (),
                      ',')
                      AS "2010",
                   c.emplid
              FROM employees a,
                   airport_tbl b,
                   pass c,
                   ps_tsa10_dnm10_vw f
             WHERE     c.emplid = a.emplid
                   AND c.emplid = f.emplid
                   AND b.tsa_airport_cd = c.tsa_airport_cd
                   AND c.tsa10_status <> 'P'
                   AND b.effdt = (SELECT MAX (effdt)
                                    FROM ps_tsa_airport_tbl
                                   WHERE tsa_airport_cd = b.tsa_airport_cd)
          GROUP BY hub_cd, c.emplid)
   WHERE    ("2008" <> ' ' AND "2009" <> ' ')
         OR ("2008" <> ' ' AND "2010" <> ' ')
         OR ("2009" <> ' ' AND "2010" <> ' ')
         OR ("2008" <> ' ' AND "2009" <> ' ' AND "2010" <> ' ')
GROUP BY hub_cd,
         emplid,
         "2008",
         "2009",
         "2010"

Answer : Union select and grouping

Is this what you mean?  http://www.washington.edu/doit/Brochures/Academics/cprep.html

Or have you already been accepted, and are just trying to get ready to leave for college in the fall?
(like this maybe?  http://www.collegeview.com/dorm_room_supply.html )
Random Solutions  
 
programming4us programming4us