पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 15 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
इस query में SELECT dept_id, COUNT(*) FROM employee GROUP BY dept_id ORDER BY ______; ख़ाली जगह पर निम्नलिखित में से क्या नहीं रखा जा सकता?
In the query SELECT dept_id, COUNT(*) FROM employee GROUP BY dept_id ORDER BY ______; which of the following CANNOT be placed in the blank?
Adept_id
BCOUNT(*)
Cename
DSUM(salary)
सही उत्तर / Answer: (C)
हल / Solution
ORDER BY समूह बनने के बाद चलता है, इसलिए उस समय केवल दो चीज़ें उपलब्ध रहती हैं — GROUP BY वाले column और समूह-फलन के मान। dept_id समूह बनाने वाला column है, तथा गिनती और योग दोनों समूह-फलन हैं, सो ये तीनों चल जाते हैं। ename न समूह बनाने वाला column है और न किसी फलन के भीतर, इसलिए एक समूह में उसके अनेक मान पड़ सकते हैं और क्रम लगाना असंभव हो जाता है — यहीं त्रुटि मिलती है।
ORDER BY runs after grouping, so only two kinds of thing are available at that moment, the GROUP BY columns and the values of group functions. Here dept_id is the grouping column, while the count and the total are both group functions, so all three work. The column ename is neither grouped nor wrapped in a function, so one group may hold many of its values and no ordering is possible, which is where the error arises.
प्रश्न 2उत्तर + हल
employee तालिका में नौ पंक्तियाँ हैं जिनके dept_id मान A, B, A, C, B, A, C, C और C हैं। इस query के परिणाम में कौन-सी पंक्ति सबसे पहले आएगी? SELECT dept_id, COUNT(*) FROM employee GROUP BY dept_id ORDER BY COUNT(*) DESC;
The employee table holds nine rows whose dept_id values are A, B, A, C, B, A, C, C and C. Which row will appear first in the output of this query? SELECT dept_id, COUNT(*) FROM employee GROUP BY dept_id ORDER BY COUNT(*) DESC;
AA, गिनती 3 के साथA with the count 3
BB, गिनती 2 के साथB with the count 2
CC, गिनती 4 के साथC with the count 4
Dत्रुटि, क्योंकि ORDER BY में समूह-फलन नहीं रखा जा सकताAn error, because a group function cannot be placed in ORDER BY
सही उत्तर / Answer: (C)
हल / Solution
पहले समूह बनते हैं और गिनती निकलती है: A की तीन पंक्तियाँ, B की दो और C की चार। ORDER BY समूह बनने के बाद चलता है, इसलिए उसमें गिनती वाले समूह-फलन का प्रयोग पूरी तरह मान्य है। DESC से बड़ी गिनती ऊपर आती है, अतः चार गिनती वाला C सबसे पहले दिखेगा, उसके बाद A और अंत में B। इसे त्रुटि मानना ग़लत है, क्योंकि ORDER BY में समूह-फलन रखने पर कोई रोक नहीं है।
Groups are formed first and the counts come out as three rows for A, two for B and four for C. ORDER BY runs after grouping, so using a counting group function there is entirely valid. DESC lifts the larger count to the top, so C with its count of four appears first, followed by A and then B. Calling it an error is wrong, since ORDER BY places no bar on a group function.
प्रश्न 3उत्तर + हल
निम्नलिखित कथन चलाने पर क्या होता है? SELECT MAX(AVG(salary)) FROM employee;
What happens when the following statement is executed? SELECT MAX(AVG(salary)) FROM employee;
Aयह तालिका का सबसे बड़ा वेतन लौटाता हैIt returns the largest salary of the table
Bयह तालिका का औसत वेतन लौटाता हैIt returns the average salary of the table
Cयह त्रुटि देता है, क्योंकि nested समूह-फलन के लिए GROUP BY clause आवश्यक हैIt raises an error, because a nested group function needs a GROUP BY clause
Dयह NULL लौटाता हैIt returns NULL
सही उत्तर / Answer: (C)
हल / Solution
भीतरी AVG बिना GROUP BY के पूरी तालिका का एक ही औसत देता है, और एक अकेले मान पर बाहरी MAX लगाने का कोई अर्थ नहीं बचता — इसीलिए दो समूह-फलन एक में रखते समय GROUP BY अनिवार्य है, जो समूहों की एक पूरी सूची बनाकर बाहरी फलन को देती है। GROUP BY के अभाव में कथन चलता ही नहीं, इसलिए यह न सर्वोच्च वेतन देता है, न औसत और न NULL।
Without GROUP BY the inner AVG yields just one average for the whole table, and applying the outer MAX to a single value carries no meaning, which is why GROUP BY is required whenever two group functions are nested; it builds a whole list of groups for the outer function to work on. Lacking GROUP BY the statement does not run at all, so it returns neither the highest salary nor the average nor NULL.
प्रश्न 4उत्तर + हल
निम्नलिखित query क्या लौटाएगी? SELECT MAX(AVG(salary)) FROM employee GROUP BY dept_id;
What will the following query return? SELECT MAX(AVG(salary)) FROM employee GROUP BY dept_id;
Aप्रत्येक विभाग का औसत वेतन, हर विभाग के लिए एक पंक्तिThe average salary of every department, one row for each department
Bविभाग-वार औसत वेतनों में से सबसे बड़ा, एक ही पंक्ति मेंThe largest among the department wise average salaries, in a single row
Cपूरी तालिका का सबसे बड़ा वेतन, एक ही पंक्ति मेंThe largest salary of the whole table, in a single row
Dत्रुटि, क्योंकि दो समूह-फलन कभी nested नहीं हो सकतेAn error, because two group functions can never be nested
सही उत्तर / Answer: (B)
हल / Solution
भीतरी AVG पहले चलता है और GROUP BY के कारण प्रत्येक विभाग का एक औसत बनाता है। बाहरी MAX उन्हीं औसतों पर लगकर उनमें से सबसे बड़ा चुनता है, इसलिए परिणाम एक ही पंक्ति का होता है। विभाग-वार सभी औसत पाने के लिए केवल AVG लिखना होता, बाहरी MAX नहीं। किसी एक कर्मचारी का सर्वोच्च वेतन इससे नहीं मिलता, क्योंकि तुलना औसतों के बीच है, और समूह-फलन का यह दो-स्तरीय nesting वर्जित नहीं है।
The inner AVG runs first and, because of GROUP BY, produces one average for each department. The outer MAX then works on those averages and picks the largest of them, so the result is a single row. To see every department average you would write AVG alone, without the outer MAX. The highest salary of one employee does not come out of this, since the comparison is among averages, and such two level nesting is not forbidden.
प्रश्न 5उत्तर + हल
employee तालिका में पाँच पंक्तियाँ हैं और उनमें से प्रत्येक का salary ठीक 25000 है। यह query क्या लौटाएगी? SELECT VARIANCE(salary), STDDEV(salary) FROM employee;
In the employee table there are five rows and the salary of every one of them is exactly 25000. What will this query return? SELECT VARIANCE(salary), STDDEV(salary) FROM employee;
A25000 और 2500025000 and 25000
B0 और 10 and 1
C0 और 00 and 0
DNULL और NULLNULL and NULL
सही उत्तर / Answer: (C)
हल / Solution
प्रसरण मानों के औसत से हटाव नापता है। यहाँ सभी मान बराबर हैं, इसलिए औसत भी 25000 है और हर पंक्ति का हटाव शून्य; शून्यों के वर्गों का जोड़ भी शून्य रहता है, सो प्रसरण शून्य है। मानक विचलन उसका वर्गमूल है, अतः वह भी शून्य। 25000 मान है, बिखराव नहीं। NULL तब मिलता जब एक भी मान न होता, पर यहाँ पाँच मान मौजूद हैं।
Variance measures how far the values stray from their mean. Here every value is the same, so the mean is also 25000 and each row deviates by zero; a sum of squared zeros is still zero, so the variance is zero. Standard deviation is its square root and is therefore zero too. The figure 25000 is a value, not a spread, and NULL would arise only with no value present.
प्रश्न 6उत्तर + हल
कौन-सा समूह फलन किसी संख्यात्मक column के प्रसरण (variance) का वर्गमूल लौटाता है?
Which group function returns the square root of the variance of a numeric column?
AAVG()
BSUM()
CCOUNT()
DSTDDEV()
सही उत्तर / Answer: (D)
हल / Solution
मानक विचलन (standard deviation) की परिभाषा ही प्रसरण का वर्गमूल है, और SQL में उसे निकालने वाला समूह फलन STDDEV है; प्रसरण स्वयं VARIANCE देता है। दोनों बिखराव नापते हैं, इसलिए साथ-साथ पढ़ाए जाते हैं। AVG केवल औसत देता है, SUM जोड़ देता है और COUNT पंक्तियाँ गिनता है — इनमें से कोई बिखराव नहीं नापता, इसलिए वे इस प्रश्न का उत्तर नहीं हो सकते।
Standard deviation is by definition the square root of the variance, and the group function that returns it in SQL is STDDEV, while the variance itself comes from VARIANCE. Both measure spread, which is why they are taught together. AVG gives only the mean, SUM gives a total and COUNT counts rows; none of them measures spread, so none can answer this question.
प्रश्न 7उत्तर + हल
employee तालिका में चार पंक्तियाँ हैं जिनके ename मान Ramesh, Anita, Suresh और Mohan हैं। यह query क्या लौटाएगी? SELECT MIN(ename) FROM employee;
The employee table holds four rows whose ename values are Ramesh, Anita, Suresh and Mohan. What will this query return? SELECT MIN(ename) FROM employee;
AAnita
BMohan
CSuresh
Dत्रुटि, क्योंकि MIN() केवल संख्यात्मक column पर चलता हैAn error, because MIN() runs only on numeric columns
सही उत्तर / Answer: (A)
हल / Solution
MIN और MAX संख्याओं के साथ-साथ अक्षर और दिनांक वाले column पर भी चलते हैं; अक्षरों में तुलना वर्णक्रम से होती है। दिए गए नामों का वर्णक्रम Anita, Mohan, Ramesh, Suresh है, इसलिए सबसे छोटा मान Anita है। Suresh वर्णक्रम में अंतिम है, सो वह MAX का उत्तर होता। MIN को केवल संख्या तक सीमित मानना भी ग़लत है, क्योंकि अक्षर वाले column पर उसे लगाने से कोई त्रुटि नहीं आती।
MIN and MAX work on character and date columns just as they do on numbers; for characters the comparison follows alphabetical order. The given names in that order read Anita, Mohan, Ramesh, Suresh, so the smallest value is Anita. Suresh stands last alphabetically, so it would be the answer for MAX instead. Calling it an error is wrong, since applying MIN to a character column raises none.
प्रश्न 8उत्तर + हल
payment तालिका में पाँच पंक्तियाँ हैं जिनके amount मान 100, 200, 100, 300 और 200 हैं। यह query क्या लौटाएगी? SELECT SUM(amount), SUM(DISTINCT amount) FROM payment;
The payment table holds five rows whose amount values are 100, 200, 100, 300 and 200. What will this query return? SELECT SUM(amount), SUM(DISTINCT amount) FROM payment;
A900 और 900900 and 900
B600 और 600600 and 600
C600 और 900600 and 900
D900 और 600900 and 600
सही उत्तर / Answer: (D)
हल / Solution
सादा SUM हर पंक्ति का मान जोड़ता है: 100+200+100+300+200 = 900। DISTINCT लगाने पर दोहराए गए मान एक-एक बार लिए जाते हैं, अतः जोड़ 100+200+300 = 600 रह जाता है। इसलिए क्रम से उत्तर 900 और 600 है। दोनों बराबर तभी होते जब किसी मान का दोहराव ही न होता, और 600 को पहले रखना दोनों रूपों को उलट देना है, जो यहाँ ग़लत है।
A plain SUM adds the value of every row: 100+200+100+300+200 = 900. With DISTINCT the repeated values are taken only once, so the total shrinks to 100+200+300 = 600. Hence the answer in order is 900 and 600. The two would be equal only if no value repeated, and putting 600 first simply swaps the two forms, which is wrong here.
प्रश्न 9उत्तर + हल
visit तालिका में सात पंक्तियाँ हैं जिनके city मान Jaipur, Kota, Jaipur, Ajmer, Udaipur, Kota और Jaipur हैं। यह query क्या लौटाएगी? SELECT COUNT(DISTINCT city) FROM visit;
The visit table holds seven rows whose city values are Jaipur, Kota, Jaipur, Ajmer, Udaipur, Kota and Jaipur. What will this query return? SELECT COUNT(DISTINCT city) FROM visit;
A4
B7
C3
D5
सही उत्तर / Answer: (A)
हल / Solution
DISTINCT लगाने पर गिनती से दोहराव हट जाता है, इसलिए हर नाम एक ही बार गिना जाता है। यहाँ भिन्न नाम चार हैं — Jaipur, Kota, Ajmer और Udaipur — अतः उत्तर चार है। सात कुल पंक्तियों की संख्या है, जो DISTINCT हटाने पर मिलती। तीन और पाँच किसी गणना से नहीं बनते; तीन तब आता जब एक शहर छोड़ दिया जाता। ध्यान रहे, DISTINCT दोहराव हटाता है, NULL की छनाई अलग नियम से होती है।
DISTINCT strips repetitions out of the count, so each name is counted just once. Here the distinct names number four, Jaipur, Kota, Ajmer and Udaipur, so the answer is four. Seven is the total row count, which is what you would get without DISTINCT. Neither three nor five follows from any correct counting. Note that DISTINCT removes duplicates, while the handling of NULL is governed by a separate rule.
प्रश्न 10उत्तर + हल
तालिका के किसी भी कर्मचारी का dept_id 99 नहीं है। निम्नलिखित query क्या लौटाएगी? SELECT COUNT(*), SUM(salary) FROM employee WHERE dept_id = 99;
No employee of the table has dept_id equal to 99. What will the following query return? SELECT COUNT(*), SUM(salary) FROM employee WHERE dept_id = 99;
A0 और 00 and 0
B0 और NULL0 and NULL
CNULL और NULLNULL and NULL
Dकोई पंक्ति नहीं, और त्रुटि मिलती हैNo row at all, and an error is raised
सही उत्तर / Answer: (B)
हल / Solution
WHERE के बाद एक भी पंक्ति न बचे, तब भी समूह-फलन वाली query एक पंक्ति देती है। COUNT इस दशा में शून्य लौटाता है, क्योंकि गिनती शून्य होना एक वैध संख्या है। पर SUM के पास जोड़ने को कुछ नहीं होता, इसलिए वह शून्य नहीं बल्कि NULL देता है — यही वह जाल है जहाँ छात्र शून्य मान बैठते हैं। त्रुटि कहीं नहीं आती, क्योंकि कथन की रचना पूरी तरह शुद्ध है।
Even when no row survives the WHERE condition, a query made of group functions still returns one row. COUNT gives zero here, since a count of zero is a perfectly valid number. SUM, however, has nothing to add up, so it yields NULL rather than zero, and that is the trap where learners assume a zero. No error arises, because the statement itself is perfectly well formed.
आगे के 15 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
employee तालिका में पाँच पंक्तियाँ हैं जिनके salary मान 2000, 4000, NULL, 6000 और NULL हैं। यह query क्या लौटाएगी? SELECT SUM(salary)/COUNT(*), AVG(salary) FROM employee;
The employee table holds five rows whose salary values are 2000, 4000, NULL, 6000 and NULL. What will this query return? SELECT SUM(salary)/COUNT(*), AVG(salary) FROM employee;
निम्नलिखित query के बारे में क्या सत्य है? SELECT SUM(salary) FROM employee GROUP BY dept_id;
What is true about the following query? SELECT SUM(salary) FROM employee GROUP BY dept_id;
Aयह त्रुटि देती है, क्योंकि dept_id SELECT सूची में नहीं हैIt raises an error, because dept_id is missing from the SELECT list
Bयह सफलतापूर्वक चलती है और प्रत्येक विभाग का एक योग देती है, पर परिणाम से यह पता नहीं चलता कि कौन-सा योग किस विभाग का हैIt runs successfully and gives one sum per department, but the output does not show which department each sum belongs to
Cयह पूरी तालिका के वेतन का कुल योग एक ही पंक्ति में लौटाती हैIt returns the salary total of the whole table in a single row
Dयह त्रुटि देती है, क्योंकि SUM() को GROUP BY के साथ प्रयोग नहीं किया जा सकताIt raises an error, because SUM() cannot be used along with GROUP BY
order_item तालिका इस प्रकार है: city | product Jaipur | Pen Jaipur | Book Kota | Pen Jaipur | Pen Kota | Book Kota | Pen यह query कितनी पंक्तियाँ लौटाएगी? SELECT city, product, COUNT(*) FROM order_item GROUP BY city, product;
The order_item table holds: city | product Jaipur | Pen Jaipur | Book Kota | Pen Jaipur | Pen Kota | Book Kota | Pen How many rows will this query return? SELECT city, product, COUNT(*) FROM order_item GROUP BY city, product;
sale तालिका इस प्रकार है: city | amount Jaipur | 500 Kota | 300 Jaipur | 700 Ajmer | 200 Kota | 400 Jaipur | 100 यह query कितनी पंक्तियाँ लौटाएगी? SELECT city, SUM(amount) FROM sale GROUP BY city;
The sale table holds: city | amount Jaipur | 500 Kota | 300 Jaipur | 700 Ajmer | 200 Kota | 400 Jaipur | 100 How many rows will this query return? SELECT city, SUM(amount) FROM sale GROUP BY city;
यह कथन SELECT dept_id, COUNT(*) FROM employee; त्रुटि देता है। इसका कारण क्या है?
The statement SELECT dept_id, COUNT(*) FROM employee; raises an error. What is the reason?
ACOUNT() के कोष्ठक में column का नाम देना सदैव आवश्यक हैCOUNT() always needs a column name inside its brackets
Bdept_id एक अकेला column है जो समूह-फलन के साथ रखा गया है, अतः उसे GROUP BY clause में आना ही चाहिएdept_id is a lone column placed beside a group function, so it must appear in a GROUP BY clause
CCOUNT(*) को SELECT सूची में रखने की अनुमति ही नहीं हैCOUNT(*) is not allowed in the SELECT list at all
Dएक SELECT सूची में दो expressions एक साथ नहीं चुने जा सकतेTwo expressions cannot be selected together in one SELECT list
marks तालिका इस प्रकार है: student | subject | marks Ravi | Maths | 80 Ravi | Science | 40 Sita | Maths | 90 Sita | Science | 70 Query P: SELECT student, AVG(marks) FROM marks WHERE marks >= 70 GROUP BY student; Query Q: SELECT student, AVG(marks) FROM marks GROUP BY student HAVING AVG(marks) >= 70; कौन-सा कथन सही है?
The marks table holds: student | subject | marks Ravi | Maths | 80 Ravi | Science | 40 Sita | Maths | 90 Sita | Science | 70 Query P: SELECT student, AVG(marks) FROM marks WHERE marks >= 70 GROUP BY student; Query Q: SELECT student, AVG(marks) FROM marks GROUP BY student HAVING AVG(marks) >= 70; Which statement is correct?
Aदोनों queries ठीक वही दो पंक्तियाँ लौटाती हैंBoth queries return exactly the same two rows
BP एक पंक्ति लौटाती है और Q दो पंक्तियाँP returns one row and Q returns two rows
Cदोनों queries असफल होती हैं, क्योंकि HAVING में AVG() नहीं रखा जा सकताBoth queries fail, because AVG() cannot be placed in HAVING
DP दो पंक्तियाँ लौटाती है जबकि Q केवल एक पंक्ति, जो Sita की हैP returns two rows while Q returns only one row, that of Sita
निम्नलिखित कथन के बारे में क्या सत्य है? SELECT MAX(salary) FROM employee HAVING MAX(salary) > 50000;
What is true about the following statement? SELECT MAX(salary) FROM employee HAVING MAX(salary) > 50000;
Aयह मान्य है; GROUP BY के अभाव में पूरी तालिका को एक ही समूह माना जाता हैIt is valid; in the absence of GROUP BY the whole table is treated as a single group
Bयह अमान्य है, क्योंकि HAVING कभी भी GROUP BY के बिना नहीं लिखा जा सकताIt is invalid, because HAVING can never be written without GROUP BY
Cयह अमान्य है, क्योंकि HAVING के भीतर MAX() की अनुमति नहीं हैIt is invalid, because MAX() is not allowed inside HAVING
Dयह केवल तब मान्य है जब salary तालिका की प्राथमिक कुंजी (Primary Key) होIt is valid only when salary is the primary key of the table
employee तालिका में निम्नलिखित पंक्तियाँ हैं: dept | salary A | 3000 A | 9000 B | 4000 B | 2000 C | 8000 निम्न query कितनी पंक्तियाँ लौटाएगी? SELECT dept, COUNT(*) FROM employee WHERE salary >= 3000 GROUP BY dept;
The employee table holds the following rows: dept | salary A | 3000 A | 9000 B | 4000 B | 2000 C | 8000 How many rows will the following query return? SELECT dept, COUNT(*) FROM employee WHERE salary >= 3000 GROUP BY dept;
निम्नलिखित कथन पर विचार कीजिए: SELECT dept_id, AVG(salary) FROM employee WHERE AVG(salary) > 20000 GROUP BY dept_id; यह कथन क्यों असफल होगा?
Consider the following statement: SELECT dept_id, AVG(salary) FROM employee WHERE AVG(salary) > 20000 GROUP BY dept_id; Why will this statement fail?
Adept_id के साथ SELECT सूची में AVG() नहीं लिखा जा सकताAVG() cannot be written in the SELECT list along with dept_id
BWHERE में group function नहीं आ सकता; ऐसी शर्त HAVING में लिखी जाती हैA group function cannot be used in the WHERE clause; such a condition belongs to HAVING
CGROUP BY हमेशा WHERE से पहले लिखा जाना चाहिएGROUP BY must always be written before WHERE
DAVG() केवल integer प्रकार के column पर ही चलता हैAVG() works only on columns of integer type