Facebook
From lalolalo, 1 Month ago, written in SQL.
Embed
Download Paste or View Raw
Hits: 148
  1. CREATE DATABASE Employees;
  2. USE Employees;
  3. CREATE TABLE student (
  4.     StudentId VARCHAR(20) PRIMARY KEY,
  5.     Name VARCHAR(50),
  6.     Age INT,
  7.     Address VARCHAR(100)
  8. );
  9.  
  10. CREATE TABLE competition (
  11.     RegistrationDate DATE,
  12.     StudentId VARCHAR(20),
  13.     RegistrationFee DECIMAL(10, 2),
  14.     CompetitionType VARCHAR(50),
  15.     FOREIGN KEY (StudentId) REFERENCES student(StudentId)
  16. );
  17.  
  18. INSERT INTO student (StudentId, Name, Age, Address) VALUES
  19. ('181-35-2222', 'Raihan', 18, 'Mirpur'),
  20. ('181-35-2224', 'Rakhi', 17, 'Ashulia'),
  21. ('181-35-2225', 'Alif', 22, 'Mirpur'),
  22. ('181-35-2226', 'Aman', 20, 'Ashulia'),
  23. ('181-35-2228', 'Niloy', 23, 'Dhanmondi');
  24.  
  25. INSERT INTO competition (RegistrationDate, StudentId, RegistrationFee, CompetitionType) VALUES
  26. ('2022-02-12', '181-35-2222', 200, 'Business Idea'),
  27.  
  28. ('2022-02-12', '181-35-2222', 300, 'Mobile App'),
  29.    ('2022-02-14', '181-35-2224', 200, 'Business Idea'),
  30. ('2022-02-15', '181-35-2225', 300, 'Mobile App'),
  31.     ('2022-02-15', '181-35-2226', 300, 'Mobile app'),
  32. ('2022-02-15', '181-35-2226', 250, 'Robotics Competition'),
  33.  
  34. ('2022-02-15', '181-35-2228', 200, 'Business Idea'),
  35.  
  36. ('2022-02-15', '181-35-2228', 300, 'Mobile App'),
  37.  
  38. ('2022-02-15', '181-35-2226', 250, 'Robotics Competition');
  39.  
  40.  
  41. SELECT * FROM competition;
  42. SELECT avg(RegistrationFee) AS AvgFee
  43. FROM competition;
  44.  
  45.  
  46.  
  47. SELECT COUNT( StudentId) AS NumofStudents
  48. FROM competition
  49. WHERE RegistrationDate = '2022-02-15';
  50.  
  51.  
  52. SELECT Name
  53. FROM Student
  54. WHERE Age >(SELECT MAX(Age) FROM Student);
  55.  
  56.  
  57.  
  58. SELECT COUNT(DISTINCT StudentId) AS NumbofStu
  59. FROM competition
  60. WHERE CompetitionType  = 'Mobile App' ;
  61.  
  62.  
  63. SELECT SUM(RegistrationFee) AS TotalFee , CompetitionType
  64. FROM competition
  65. GROUP BY CompetitionType;
  66.  
  67. SELECT DISTINCT StudentId FROM competition;
  68.  
  69. SELECT Studentid
  70. FROM student
  71. WHERE Name LIKE 'N%';
  72.  
  73. SELECT *
  74. FROM student
  75. WHERE  Age < 22 AND  Address = 'Mirpur';
  76.  
  77.  
  78. SELECT Address
  79. FROM Student
  80. WHERE StudentId IN(
  81.    SELECT DISTINCT StudentId
  82.    FROM competition
  83.     WHERE Competiti Competition" );
  84.  
  85.   select Name
  86.   from student
  87.   where Age > ANY (Select Age from student where Address = "Mirpur" );
  88.  
  89.  
  90.   delete from student
  91.   where Address = "Ashulia" ;

Replies to Untitled rss

Title Name Language When
Re: Untitled lalolalolalo sql 1 Month ago.