database - SQL QUERY Error :subquery returns more than one row -
i newbie sql , database learning , trying solve following database problem:
we have table 2 column name , marks. write query based on table returns grades if marks if greater 700, 'a' if less 700 , greater 500, 'b' or 'c'. main point table has 2 column.
here's query:
create table class (name varchar(20),marks int); insert class values ("anu",1000),("abhi",100),("mittal",800),("chanchal",1200),("gurpreet",750),("somesh",1000),("sonia",600),("khushbu",450),("rashi",1100),("jyoti",550); select * class;
it shows following table:
| name | marks | | anu | 1000 | | abhi | 100 | | mittal | 800 | | chanchal | 1200 | | gurpreet | 750 | | somesh | 1000 | | sonia | 600 | | khushbu | 450 | | rashi | 1100 | | jyoti | 550 |
select * class grade =(select case when marks >700 "a" when marks<700 , marks<700 "b" else "c" end grade class);
it shows following error:
error 1242 (21000): subquery returns more 1 row
need last command.
select name , case when marks >700 'a' when marks<700 , marks<700 'b' else 'c' end grade class
the above query should fulfill need , display name , grades according criteria set you. hope sql meant sql server.
Comments
Post a Comment