MySQL-এ WHERE ক্লজ ব্যবহার করে নির্দিষ্ট স্কোরের চেয়ে বেশি স্কোর পাওয়া ছাত্রদের রেকর্ড বের করা সহজ এবং সরাসরি।
টেবিল তৈরি এবং ডেটা ইনসার্ট
mysql> CREATE TABLE DemoTable (
-> Id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> StudentName VARCHAR(100),
-> StudentScore INT
-> );
Query OK, 0 rows affected (1.65 sec)
mysql> INSERT INTO DemoTable(StudentName, StudentScore) VALUES('John', 43);
mysql> INSERT INTO DemoTable(StudentName, StudentScore) VALUES('Sam', 48);
mysql> INSERT INTO DemoTable(StudentName, StudentScore) VALUES('Chris', 33);
mysql> INSERT INTO DemoTable(StudentName, StudentScore) VALUES('Robert', 89);
সব রেকর্ড দেখানো
mysql> SELECT * FROM DemoTable;
আউটপুট
+----+-------------+--------------+ | Id | StudentName | StudentScore | +----+-------------+--------------+ | 1 | John | 43 | | 2 | Sam | 48 | | 3 | Chris | 33 | | 4 | Robert | 89 | +----+-------------+--------------+ 4 rows in set (0.00 sec)
৪৫ নম্বরের বেশি স্কোর পাওয়া ছাত্ররা
mysql> SELECT StudentName FROM DemoTable WHERE StudentScore > 45;
আউটপুট
+-------------+ | StudentName | +-------------+ | Sam | | Robert | +-------------+ 2 rows in set (0.00 sec)
ব্যাখ্যা: WHERE StudentScore > 45 শর্তে ৪৫-এর চেয়ে বড় স্কোর वाले রো বের হয়েছে। Sam (৪৮) এবং Robert (৮৯) পাওয়া গেলো।
বিকল্প অপারেটর:
>=— ৪৫ বা তার বেশি<— ৪৫-এর কমBETWEEN 45 AND 90— ৪৫ থেকে ৯০ পর্যন্ত (ইনক্লুসিভ)
সর্ট সহ: SELECT StudentName, StudentScore FROM DemoTable WHERE StudentScore > 45 ORDER BY StudentScore DESC; — সর্বোচ্চ স্কোর প্রথমে।