locked
Query RRS feed

  • Question

  • Please help me in the query to find out ...
    Student-Record (STU_ID , STU_NAME , SEM_NO , TOTAL_MARKS)
    SQL query on Student-Record table to find the total number of students that have total marks higher than the average marks in Class...
    Tuesday, August 27, 2019 2:20 AM

Answers

All replies

  • Good day Saad and welcome to the MSDN forums,

    When you post a question (or any message) then you must remember that the readers cannot read minds and they cannot see what you see or control the database which you use. Therefore, you must start from the beginning and provide all the information in order to reproduce your case.

    If you have question regarding a table then we need to have the ability to create the exact same table in our environment (our server).

    It is true that we can guess what is the table's structure, but why guess when you can provide the information?!? Moreover, we only have the names of the columns and no information about their types or about indexes and so one...

    And above all!, let the members in the forum to focus on helping and focus on your issue instead of spending their time working on something which you can do.

    For any question which is related to queries you should provide:

    1) Queries to CREATE your table(s) including indexes
    2) Queries  to INSERT sample data.
    3) The desired result given the sample, as text or image of excel for example.
    4) A short description of the business rules, and how you got 1-2 of the results
    5) Which version of SQL Server you are using (this will help to fit the query to your version).

    * If you do not know how to provide one of these then please inform us and we will help in that step, as this is what you should provide in any forum in any question related to queries.

    In the meantime, 
    Have a great day😃


    signature   Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]    [Linkedin]



    • Edited by pituachMVP Tuesday, August 27, 2019 4:09 AM
    Tuesday, August 27, 2019 3:47 AM

  • SQL query on Student-Record table to find the total number of students that have total marks higher than the average marks in Class...

    Does below work?

    SELECT count(*)
    FROM [Student-Record]
    WHERE [TOTAL_MARKS] > (
    		SELECT AVG([TOTAL_MARKS])
    		FROM [Student-Record]
    		)

    Please see below for such queries:

    https://www.plus2net.com/sql_tutorial/sql_avg.php


    Cheers
    Vaibhav
    MCSA (SQL Server 2014)

    Tuesday, August 27, 2019 4:54 AM
  • Try

    SELECT  * FROM(

    SELECT *,(SELECT AVG (TOTAL_MARKS) FROM tbl) AVG_Marks

    ) AS Der WHERE TOTAL_MARKS>AVG_Marks


    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance
    SQL Server Integration Services: Business Intelligence

    Wednesday, August 28, 2019 4:56 AM