Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.43 KB | None | 0 0
  1. CREATE TABLE PET_3 (
  2.   id INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  3.   PetName VARCHAR(30) NOT NULL,
  4.   PetType VARCHAR(30) NOT NULL,  
  5.   PetBreed VARCHAR(30) NOT NULL,
  6.   PetDOB VARCHAR(30) NOT NULL,
  7.   PetWeight DECIMAL(5,2) NOT NULL,
  8.   OwnerID INTEGER UNSIGNED NOT NULL
  9. );
  10.  
  11. INSERT INTO `PET_3` (`PetName`, `PetType`, `PetBreed`, `PetDOB`, `PetWeight`, `OwnerID`) VALUES ('King', 'Dog', 'Std. Poodle', '27-Feb-11', 25.5, 1);
  12. INSERT INTO `PET_3` (`PetName`, `PetType`, `PetBreed`, `PetDOB`, `PetWeight`, `OwnerID`) VALUES ('King', 'Dog', 'Std. Poodle', '27-Feb-11', 10.5, 2);
  13. INSERT INTO `PET_3` (`PetName`, `PetType`, `PetBreed`, `PetDOB`, `PetWeight`, `OwnerID`) VALUES ('King', 'Dog', 'Std. Poodle', '27-Feb-11', 28.5, 3);
  14. INSERT INTO `PET_3` (`PetName`, `PetType`, `PetBreed`, `PetDOB`, `PetWeight`, `OwnerID`) VALUES ('King', 'Dog', 'Cashmere', '27-Feb-11', 9.5, 4);
  15. INSERT INTO `PET_3` (`PetName`, `PetType`, `PetBreed`, `PetDOB`, `PetWeight`, `OwnerID`) VALUES ('King', 'Dog', 'Cashmere', '27-Feb-11', 25, 5);
  16. INSERT INTO `PET_3` (`PetName`, `PetType`, `PetBreed`, `PetDOB`, `PetWeight`, `OwnerID`) VALUES ('King', 'Dog', 'Cashmere', '27-Feb-11', 20.0, 6);
  17. INSERT INTO `PET_3` (`PetName`, `PetType`, `PetBreed`, `PetDOB`, `PetWeight`, `OwnerID`) VALUES ('King', 'Dog', 'Unknow', '27-Feb-11', 30, 7);
  18.  
  19.  
  20. SELECT AVG(PetWeight) AS AverageWeight, PetBreed, COUNT(PetBreed) AS PetCount
  21. FROM PET_3
  22. GROUP BY `PetBreed`
  23. HAVING PetCount > 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement