import callin.*;
import callout.*;
public class stu_aggregation
{
public stu_aggregation(){}
public void sum_age_sysfunc(CallContext cxt, Tuple tpl) throws AmosException
{
try
{
Connection theconnection=new Connection("");
Scan scan = theconnection.execute("sum(select x from integer x,Student s where x=age(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ");");
System.out.println("专业: " + tpl.getStringElem(0) + " 的");
System.out.println("总年龄为: " + scan.getRow().getIntElem(0));
}
catch(AmosException e)
{
throw(e);
}
}
public void sum_age_user_d_func(CallContext cxt, Tuple tpl) throws AmosException
{
try
{
int sum_age = 0;
int age_temp = 0;
Connection theconnection=new Connection("");
Scan scan = theconnection.execute("select name, age from integer age, charstring name, Student s where age=age(s) and name=name(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ";");
System.out.println("姓名 " + "年龄");
while(!scan.eos())
{
Tuple thetpl = scan.getRow();
System.out.printf("%-12s %d\n", thetpl.getStringElem(0), thetpl.getIntElem(1));
age_temp = thetpl.getIntElem(1);
sum_age += age_temp;
scan.nextRow();
}
System.out.println("专业: " + tpl.getStringElem(0) + " 的");
System.out.println("总年龄为: " + sum_age);
}
catch(AmosException e)
{
throw(e);
}
}
public void avg_age(CallContext cxt, Tuple tpl) throws AmosException
{
try
{
Connection theconnection=new Connection("");
int avg_age = 0;
int total_age = 0;
int count = 0;
Scan scan = theconnection.execute("sum(select x from integer x,Student s where x=age(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ");");
total_age = scan.getRow().getIntElem(0);
scan = theconnection.execute("count(select x from integer x,Student s where x=age(s) and Speciality(s)=" + "\"" + tpl.getStringElem(0) + "\"" + ");");
count = scan.getRow().getIntElem(0);
avg_age = total_age / count;
System.out.println("专业: " + tpl.getStringElem(0) + " 的");
System.out.println("专业人数: " + count);
System.out.println("总年龄为: " + total_age);
System.out.println("平均年龄为: " + avg_age);
}
catch(AmosException e)
{
throw(e);
}
}
public void age(CallContext cxt, Tuple tpl) throws AmosException
{
try
{
Connection theconnection=new Connection("");
int age;
Scan thescan = theconnection.execute("select x from integer x, Person p where x=age(p) and name(p)="
+ "\"" + tpl.getStringElem(0) + "\"" + ";");
System.out.println("年龄: " + thescan.getRow().getIntElem(0));
}
catch(AmosException e)
{
throw(e);
}
}
}
|