ये सभी प्रश्न आपको SQL सर्वर मानकों का अनुपालन करने वाले किसी भी SQL प्लेटफॉर्म पर सिंटैक्स त्रुटि प्रदान करेंगे।
SELECT * FROM plant ORDER BY SUM(id);
SELECT * FROM plant ORDER BY COUNT(fruit);
SELECT * FROM plant ORDER BY COUNT(*);
SELECT * FROM plant ORDER BY SUM(1) DESC;
PostgreSQL पर, उदाहरण के लिए, उन सभी प्रश्नों में एक ही त्रुटि होगी।
ERROR: column "plant.id" must appear in the GROUP BY clause or be used in an aggregate function
इसका मतलब है कि आप GROUP BY का उपयोग किये बिना डोमेन समेकित फ़ंक्शन का उपयोग कर रहे हैं। एसक्यूएल सर्वर और ओरेकल समान त्रुटि संदेश लौटते हैं।
माईएसक्यूएल ग्रुप बी को कम से कम मानक व्यवहार के संबंध में कई मामलों में तोड़ने के लिए जाना जाता है। लेकिन आपके द्वारा पोस्ट किए गए प्रश्न मेरे लिए एक नया टूटा व्यवहार था, इसलिए इसके लिए +1।
यह समझने की कोशिश करने के बजाय कि यह हुड के तहत क्या कर रहा है, आप शायद मानक ग्रुप बाय प्रश्नों को लिखने के लिए सीखने से बेहतर हैं। जहां तक मुझे पता है, MySQL प्रक्रिया मानक ग्रुप बाय स्टेटमेंट सही तरीके से करेगा।
MySQL दस्तावेज़ों के पहले संस्करणों ने आपको ग्रुप बाय और छुपा कॉलम के बारे में चेतावनी दी थी। (मैं एक संदर्भ नहीं है, लेकिन इस पाठ हर जगह उद्धृत किया जाता है।)
Do not use this feature if the columns you omit from the GROUP BY part are not constant in the group. The server is free to return any value from the group, so the results are indeterminate unless all values are the same.
More recent versions are a little different।
You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate.
व्यक्तिगत रूप से, मैं अनिश्चित एसक्यूएल में एक सुविधा पर विचार नहीं करते।
उत्कृष्ट स्पष्टीकरण, धन्यवाद! – nawfal