public function getComparisonStudentsByMonth()
{
$last_month = date('m', strtotime('-2 month'));
$previus_month = date('m', strtotime('-1 month'));
return
$this->db->select('MONTH('student_add_date')', date('m'));
$this->db->where('student_add_date <= DATE_ADD(NOW(),INTERVAL 30 DAYS)');
$query = $this->db->get('students')->result();
}
用户每月插入新学生和管理页面应显示月份之间的百分比比较。我应该像上个月那样100%与当月比较。我理解逻辑但是如何处理MySql。
答案 0 :(得分:0)
要获得每个月的所有百分比,您可以使用它:
out = 10
两个月之间需要在查询中指定月份。例如,我将在9月(9)和oktober(10)
搜索SELECT (MONTH(student_add_date)) AS month_temp, ((count(*) /(SELECT count(*) FROM students)) * 100)percentage from students group by month_temp
在codeigniter中,您可以像这样运行自定义查询:
SELECT
(MONTH(student_add_date)) AS month_temp,
((count(*) /(SELECT count(*) FROM students WHERE MONTH(student_add_date) = 9 OR MONTH(student_add_date) = 10)) * 100)percentace
from students
WHERE
MONTH(student_add_date) = 9
OR
MONTH(student_add_date) = 10
group by month_temp
答案 1 :(得分:0)
public class AlarmReceiver extends BroadcastReceiver {
GPSTracker gps;
double newLat, newLong;
String aString;
String bString;
@Override
public void onReceive(Context context, Intent intent) {
updateYourActivity(context);
}
private void updateYourActivity(Context context) {
Intent intent = new Intent("some_unique_name");
// put whatever data you want to send, if any
// intent.putExtra("message", message);
gps = new GPSTracker(context);
// check if GPS enabled
if(gps.canGetLocation()){
newLat = gps.getLatitude();
newLong = gps.getLongitude();
aString = Double.toString(newLat);
bString = Double.toString(newLong);
// lat1.setText(""+latitude);
//long1.setText(""+longitude);
Log.e("new lat",""+aString);
Log.e("new long",""+bString);
}else{
gps.showSettingsAlert();
}
intent.putExtra("lat", aString);
intent.putExtra("long", bString);
context.sendBroadcast(intent);
}
}