Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:05:56+00:00 2026-06-17T16:05:56+00:00

I have this Data in DB CREATE TABLE Stu_Table ( Stu_Id VARCHAR(2), Stu_Name VARCHAR(15),

  • 0

I have this Data in DB

CREATE TABLE Stu_Table
(
    Stu_Id VARCHAR(2),
    Stu_Name VARCHAR(15), 
    Stu_Class VARCHAR(10),
    sub_id VARCHAR(2),
    marks VARCHAR(3)
);

INSERT INTO Stu_Table VALUES (1, 'Komal', 10, 1, 45);
INSERT INTO Stu_Table VALUES (2, 'Ajay', 10, 1, 56);
INSERT INTO Stu_Table VALUES (3, 'Rakesh', 10, 1, 67);
INSERT INTO Stu_Table VALUES (1, 'Komal', 10, 2, 47);
INSERT INTO Stu_Table VALUES (2, 'Ajay', 10, 2, 53);
INSERT INTO Stu_Table VALUES (3, 'Rakesh', 10, 2, 57);
INSERT INTO Stu_Table VALUES (1, 'Komal', 10, 3, 45);
INSERT INTO Stu_Table VALUES (2, 'Ajay', 10, 3, 56);
INSERT INTO Stu_Table VALUES (3, 'Rakesh', 10, 3, 67);
INSERT INTO Stu_Table VALUES (1, 'Komal', 10, 4, 65);
INSERT INTO Stu_Table VALUES (2, 'Ajay', 10, 4, 56);
INSERT INTO Stu_Table VALUES (3, 'Rakesh', 10, 4, 37);
INSERT INTO Stu_Table VALUES (1, 'Komal', 10, 5, 65);
INSERT INTO Stu_Table VALUES (2, 'Ajay', 10, 5, 46);
INSERT INTO Stu_Table VALUES (3, 'Rakesh', 10, 5, 63);

And I’m doing this query on this data.

SELECT *
FROM
(
    SELECT
        Stu_Id,
        MIN(marks) AS mini,
        AVG(marks) AS per
    FROM stu_table
    GROUP BY stu_id
    HAVING MIN(marks) > 45
);

And I’m getting this:

Stu_Id| mini  |  per
   1  |  45   |  53.4
   2  |  46   |  53.4
   3  |  37   |  58.2

I don’t understand why I still see Stu_Id 1 with min(mark)=45 when I clearly have this HAVING min(marks)>45 in my query.

Runnable Demo

FIX:
Thanks to @sybkar and @Martin Smith!

I set the marks type as a string.
It’s should be INT…

Thanks guys!
Working perfect!

create table Stu_Table(Stu_Id INT(2), Stu_Name varchar(15), 
Stu_Class  varchar(10),sub_id INT(2),marks INT(3));<--INT!!!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:05:57+00:00Added an answer on June 17, 2026 at 4:05 pm

    I don’t understand why I still see Stu_Id 1 with min(mark)=45
    when I clearly have this HAVING min(marks)>45 in my query.

    You don’t. Or at the least the demo you have provided doesn’t.

    In general any weird results that you are getting will be because marks is being stored as a string so MIN(marks) will be bringing back the earliest in alphabetical order though.

    For example HAVING MIN(marks) > 45 will also bring back 5, 6, 7, 8 and 9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, if I have this data: CREATE TABLE FooBar ( Name varchar(16) )
We have this data set: CREATE TABLE #Changes ( [GUID] varchar(250), Value numeric(36,6), DocumentNumber
If I have a table column with data and create an index on this
I have this table: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255)
I have some nicely-structured data that looks like this: CREATE TABLE SourceBodyPartColors ( person_ID
I have this data: Create Table #Some ( ForeignId Int , SubValue UniqueIdentifier ,
I have this SQL table: CREATE TABLE DATA ( ID NUMBER NOT NULL, CODE
I have the following Query: create table #Result (Reward varchar(40), Value MONEY); insert #Result
I am trying to insert some data into a table I created. I have
I have some data and need to create a json file with this structure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.