GSD Questions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
696 B

7 years ago
  1. SET FEEDBACK OFF
  2. DROP TABLE T;
  3. CREATE TABLE T (A INT, B VARCHAR(16), C INT);
  4. INSERT INTO T VALUES (1, 'blue', 10);
  5. INSERT INTO T VALUES (2, 'blue', 40);
  6. INSERT INTO T VALUES (3, 'pink', 30);
  7. INSERT INTO T VALUES (4, 'orange', 10);
  8. INSERT INTO T VALUES (5, 'orange', 20);
  9. INSERT INTO T VALUES (6, 'orange', 50);
  10. INSERT INTO T VALUES (7, 'orange', 50);
  11. INSERT INTO T VALUES (8, 'black', 50);
  12. INSERT INTO T VALUES (9, 'black', 40);
  13. INSERT INTO T VALUES (10, 'violet', 10);
  14. INSERT INTO T VALUES (11, 'violet', 20);
  15. INSERT INTO T VALUES (12, 'violet', 10);
  16. SET FEEDBACK ON
  17. SELECT B, COUNT(*) FROM T GROUP BY B HAVING SUM(C)<=40;
  18. SELECT B, COUNT(*) FROM T WHERE C>35 GROUP BY B HAVING COUNT(*)>=2;