0

following is the bash script I wrote for Sqlite.

 #!/bin/bash
 sqlite3 file.db "CREATE TABLE table1(name text,rolln integer PRIMARY KEY,examm integer CHECK(examm >=0 and examm <= 50));"
 sqlite3 file.db "insert into table1(name,rolln,examm)values('Aldose Paul ',1234,'alpj@gmail.com',49); "
 sqlite3 file.db "insert into table1(name,rolln,examm)values('Thomas Paul',1023,'tpaul@gmail.com',45); "

 sqlite3 file.db "CREATE TABLE project(title text PRIMARY KEY,marks integer CHECK(marks >= 0 and marks <= 20)) ;"
 sqlite3 file.db "insert into project(title,marks)values('A',16);"
 sqlite3 file.db "insert into project(title,marks)values('B',14);"


 sqlite3  file.db "select rolln AS 'Roll Number' ,(examm) AS 'Total Marks'from table1 order by (examms ) ;"
4

1 回答 1

0

As a starter, here is one way to get the rank depending on the grade:

.headers on

create table foo (name text, grade int);

insert into foo values ('Joe', 45);
insert into foo values ('Anna', 98);
insert into foo values ('Julie', 78);

select name, 
       grade, 
       (select count(*) from foo t1 where t1.grade>=t2.grade) as rank  
from foo t2;

select name, 
       grade, 
       (select count(*) from foo t1 where t1.grade>=t2.grade) as rank  
from foo t2
order by rank;

Having saved this as foo.sql, I get this:

[someone@somewhere tmp]$ sqlite3 < foo.sql 
name|grade|rank
Joe|45|3
Anna|98|1
Julie|78|2
name|grade|rank
Anna|98|1
Julie|78|2
Joe|45|3
于 2012-04-08T12:51:01.520 回答