我想知道在1小时,1到2小时和超过2小时内预约的次数。
/* sample redux fields = array(
array(
'id' => 'theme-primary-color',
'type' => 'color',
'title' => __( 'Add Primary Color', 'theme-redux' ),
'subtitle' => __( 'Add the theme primary color', 'theme-redux' ),
'default' => '#FFFFFF',
'validate' => 'color',
'compiler' => 'true',
))
*/
add_filter('redux/options/' . $opt_name . '/compiler', 'compiler_action', 10,3);
function compiler_action( $options, $css, $changed_values ) {
global $wp_filesystem, $kavabase_options;
$filename = get_template_directory() . '/assets/stylesheets/theme-style.css';
if( empty( $wp_filesystem ) ) {
require_once( ABSPATH .'/wp-admin/includes/file.php' );
WP_Filesystem();
}
if( $wp_filesystem ) {
require_once ( dirname(__FILE__ ) ."/plugins/scssphp/scss.inc.php" );
//use Leafo\ScssPhp\Compiler; at the beginning of the file
$scss = new Compiler();
$scss->setImportPaths( get_template_directory(). "/inc/foundation-sites/" );
//$scss->setFormatter( "Leafo\ScssPhp\Formatter\Compressed" );
$css = $scss->compile('@import "foundationdependencies.scss"; $theme-primary-color: '.$options['theme-primary-color'].';
@import "foundationsettings.scss";
@import "foundationutil.scss";@import "foundation.scss"');
//var_dump( $scss->getParsedFiles() );
$wp_filesystem->put_contents(
$filename,
$css,
FS_CHMOD_FILE // predefined mode settings for WP files
);
}
}
count方法返回以下异常:
Appointment
.select("id, EXTRACT(MINUTE FROM (check_out_at - check_in_at)) as minutes")
.group("id, minutes")
.having("count('minutes') < 60")
.count
答案 0 :(得分:0)
假设id
是主键,您既不需要group by
也不需要having
。您只需执行此操作即可获得1小时以内的约会计数:
Appointment.where("(EXTRACT(epoch FROM (check_out_at - check_in_at))) < 3600").count
要计算按小时分组的所有约会,您可以执行以下操作:
Appointment.group("Floor(Extract(epoch from (check_out_at - check_in_at))/3600)").count
输出如下:
{0.0=>1, 2.0=>31, 3.0=>11}
意味着0-1小时之间预约1次,31小时之间约2-3小时等等。