set @totalS = 0;
select count(*) into @totalS from exammarks;
SELECT exammarks.stdid, (exammarks.Test1 + exammarks.Test2 + exammarks.Test3 + exammarks.Test4)/4 AS avge, @curRank :=
IF(@prevVal=(exammarks.Test1 + exammarks.Test2 + exammarks.Test3 + exammarks.Test4)/4, @curRank, @studentN) AS rank,
@percentile := IF(@prevVal=(exammarks.Test1 + exammarks.Test2 + exammarks.Test3 + exammarks.Test4)/4, @percentile,
(@totalS - @studentN + 1)/(@totalS)*100) as percent,
@studentN := @studentN + 1 as studentN,
@prevVal:=(exammarks.Test1 + exammarks.Test2 + exammarks.Test3 + exammarks.Test4)/4 as totagain
FROM exammarks, (
SELECT @curRank :=0, @prevVal:=null, @studentN:=1, @percentile:=100
) r
ORDER BY (exammarks.Test1 + exammarks.Test2 + exammarks.Test3 + exammarks.Test4)/4 DESC
Experienced Software Engineer with a demonstrated history of working in the information technology and services industry. Skilled in .net,C#, sql Database,R programming, Android and JavaScript. Strong engineering professional with a Master’s Degree focused in MPhil in Advanced Computer Science from University of Cambridge.
Sunday, May 5, 2013
The Biggest Sql statement which i used..
This is the biggest query i used during my development life up to now.this query retrieves students with their ranks.when two students got same marks they are having same rank and next person will be 1 after their rank.so this query gives practical ranking functionality.
Saturday, May 4, 2013
IOS Easy Apps
IOS apllications are not much hard when we used to develop them.those are few small apps which i used to create.You can try them out by coping and pasying those codes to relavant classes.
Animation
.h
#import <UIKit/UIKit.h>
@interface AnimationViewController : UIViewController {
IBOutlet UIView
*mover;
IBOutlet UIView
*grower;
IBOutlet UIView
*changer;
}
@property(nonatomic,retain)UIView *mover;
@property(nonatomic,retain)UIView *grower;
@property(nonatomic,retain)UIView *changer;
-(IBAction)move;
-(IBAction)grow;
-(IBAction)change;
@end
.m
#import "AnimationViewController.h"
@implementation AnimationViewController
@synthesize
grower,changer,mover;
-(IBAction)move
{
[UIView
beginAnimations:nil context:NULL];
[UIView
setAnimationDuration:3.0];
[UIView
setAnimationRepeatCount:5];
changer.backgroundColor = [UIColor orangeColor];
CGPoint
cPoint=mover.center;
cPoint.y=220.0f;
mover.center=cPoint;
[UIView
commitAnimations];
}
-(IBAction)change
{
[UIView
beginAnimations:nil context:NULL];
[UIView
setAnimationDuration:3.0];
[UIView
setAnimationRepeatCount:5];
changer.backgroundColor = [UIColor redColor];
[UIView commitAnimations];
}
-(IBAction)grow
{
[UIView
beginAnimations:nil context:NULL];
[UIView
setAnimationDuration:3.0];
[UIView
setAnimationRepeatCount:5];
CGRect
a=grower.bounds;
a.size.height=200.0f;
a.size.width=200.0f;
grower.bounds=a;
//assigning bounds tot he shapes
[UIView
commitAnimations];
}
- (void)dealloc
{
[super
dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases
the view if it doesn't have a superview.
[super
didReceiveMemoryWarning];
// Release any cached data, images, etc that
aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after
loading the view, typically from a nib.
- (void)viewDidLoad
{
[super
viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super
viewDidUnload];
// Release
any retained subviews of the main view.
// e.g.
self.myOutlet = nil;
}
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return
YES for supported orientations
return
(interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
ColorPicker
.h
#import <UIKit/UIKit.h>
@interface Lab2ViewController : UIViewController
<UIPickerViewDelegate,UIPickerViewDataSource>
{
NSArray *colors;
IBOutlet
UIPickerView * colorPicker;
}
@property(nonatomic,retain) UIPickerView *colorPicker;
@end
.m
#import "Lab2ViewController.h"
@implementation Lab2ViewController
@synthesize colorPicker;
//methods for UIPickerViewDataSource
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView
*)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
return
colors.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return
[colors objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
UIColor
*newColor;
switch
(row){
case
0:case 1: case 2:
newColor = [UIColor yellowColor];
break;
case
3: case 4: case 5:
newColor = [UIColor grayColor];
break;
case
6: //case 7:
newColor
= [UIColor blackColor];
break;
default:
newColor = [UIColor redColor];
break;
}
self.view.backgroundColor = newColor;
}
- (void)dealloc
{
[super
dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases
the view if it doesn't have a superview.
[super
didReceiveMemoryWarning];
// Release
any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after
loading the view, typically from a nib.
- (void)viewDidLoad
{
colors =
[[NSArray
alloc]initWithObjects:@"Blue",@"Yellow",@"Pink",
@"Fine",@"Tired",@"Maudlin",
@"Purple",@"Green",nil];
[super
viewDidLoad];
}
- (void)viewDidUnload
{
[super
viewDidUnload];
// Release
any retained subviews of the main view.
// e.g.
self.myOutlet = nil;
}
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return
YES for supported orientations
return
(interfaceOrientation == UIInterfaceOrientationPortrait);
}@end
Database
.h
#import "/usr/include/sqlite3.h"
@interface databasesqliteViewController :
UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
NSString *databasePath;
sqlite3 *contactDB;
}
@property (retain, nonatomic) IBOutlet UITextField
*name;
@property (retain, nonatomic) IBOutlet UITextField
*address;
@property (retain, nonatomic) IBOutlet UITextField
*phone;
@property (retain, nonatomic) IBOutlet UILabel
*status;
-(IBAction)saveData;
-(IBAction)findContact;
@end
.m
#import "databasesqliteViewController.h"
@implementation databasesqliteViewController
@synthesize name, address, phone, status;
- (void) saveData
{
sqlite3_stmt
*statement;
const char
*dbpath = [databasePath UTF8String];
if
(sqlite3_open(dbpath, &contactDB) == SQLITE_OK) {
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO
CONTACTS (name, address, phone) VALUES (\"%@\", \"%@\",
\"%@\")", name.text, address.text, phone.text];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
if
(sqlite3_step(statement) == SQLITE_DONE) {
status.text = @"Contact added";
name.text = @"";
address.text = @"";
phone.text = @"";
}
else
{
status.text
= @"Failed to add the contact";
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
}
- (void) findContact
{
sqlite3_stmt *statement;
const
char *dbpath = [databasePath UTF8String];
if
(sqlite3_open(dbpath, &contactDB) == SQLITE_OK) {
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO
CONTACTS (name, address, phone) VALUES (\"%@\", \"%@\",
\"%@\")", name.text, address.text, phone.text];
const
char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
if
(sqlite3_step(statement) == SQLITE_DONE) {
status.text = @"Contact added";
name.text = @"";
address.text = @"";
phone.text = @"";
}
else
{
status.text = @"Failed to SEARC the contact";
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
}
-
(void)dealloc
{
[super
dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases
the view if it doesn't have a superview.
[super
didReceiveMemoryWarning];
//
Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after
loading the view, typically from a nib.
- (void)viewDidLoad
{
NSString
*docsDir;
NSArray
*dirPaths;
//get the
documents directory
dirPaths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES);
docsDir =
[dirPaths objectAtIndex:0];
//build the
path to the database file
databasePath = [[NSString alloc] initWithString:[docsDir
stringByAppendingPathComponent:@"contacts.db"]];
NSFileManager *filemgr = [NSFileManager
defaultManager];
if
([filemgr fileExistsAtPath:databasePath] == NO) {
const char
*dbpath = [databasePath UTF8String];
if
(sqlite3_open(dbpath, &contactDB) == SQLITE_OK) {
char
*errMsg;
const char *sql_stmt = "CREATE TABLE IF NOT EXISTS CONTACTS(ID
INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, ADDRESS TEXT, PHONE TEXT)";
if
(sqlite3_exec(contactDB, sql_stmt, NULL, NULL, &errMsg) != SQLITE_OK) {
status.text = @"Failed to create
table";
}
sqlite3_close(contactDB);
}
else
{
status.text = @"Failed to open/create database";
}
}
[filemgr
release];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super
viewDidUnload];
// Release
any retained subviews of the main view.
// e.g.
self.myOutlet = nil;
}
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{ // Return
YES for supported orientations
return
(interfaceOrientation == UIInterfaceOrientationPortrait);
}@end
Views
.m
#import "mad_lastViewController.h"
@implementation mad_lastViewController
NSArray *myarray;
- (void)dealloc
{
[super
dealloc];
}
- (UITableViewCell *)tableView:(UITableView
*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static
NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell==nil)
{
cell =
[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [myarray objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"Blue hills.jpg"];
return cell;
}-
(void)didReceiveMemoryWarning
{
// Releases
the view if it doesn't have a superview.
[super
didReceiveMemoryWarning];
//
Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after
loading the view, typically from a nib.
- (void)viewDidLoad
{
myarray =
[NSArray
arrayWithObjects:@"A",@"B",@"C",@"D",
nil];
[super
viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return
[myarray count];
}
- (void)viewDidUnload
{
[super
viewDidUnload];
// Release
any retained subviews of the main view.
// e.g.
self.myOutlet = nil;
}
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{ // Return
YES for supported orientations
return
(interfaceOrientation == UIInterfaceOrientationPortrait);
}@end
Subscribe to:
Posts (Atom)