Skip to content
Advertisement

Problem in using group by statement in sql

I am not able to group by table which has all the values same but has two rows. I am not understanding what is the reason behind that.

After running this query i am getting the table below and i want to group the table along the LOT_No.

TABLE :

Now when i am trying to Group by LOT_No, i am getting below error.

I also tried to take all columns from SELECT statement, but then i got this error

I am totally confused what is going on. Can anyone please help.

Advertisement

Answer

There are multiple issues in your query.

  • group by c.lot_no is required
  • Second expression in SELECT must be wrapped in SUM aggregate function. (change the expression of CASE statement according to requirement)
  • Always use the standard ANSI-join. (Recommended)

Check the below solution:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement