我正在使用 PHP 并尝试在 MySQL 上执行查询,
当我使用 MySqlYog 执行此查询时,我得到了结果,一切似乎都正常。
查询:
SELECT
start_time AS `Date`,
COUNT(1) AS `Count`
FROM
offline_execution_jobs
WHERE start_time >= NOW() - INTERVAL 365 DAY
AND application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT'
GROUP BY (WEEK(start_time))
ORDER BY `Date` ASC ;
但问题是当我试图从 PHP 执行查询时:
我收到这个错误:
Invalid query: 'nolio_db.offline_execution_jobs.start_time' isn't in GROUP BY
如果有人遇到过这个问题,我会很高兴听到如何克服它?
我需要 GROUP BY 的输出格式如下:
第一列为 DATE 格式的一周的第一天,第二列为事件计数。
2011-01-09 03:28:54 | 38
最佳答案
如果您按 start_time 的 WEEK 分组,那么这就是您应该选择的内容(而不是日期本身)。否则,您将如何报告计数?您想要显示每周的计数,而不是每个日期的计数。
您的 where 子句中也存在语义错误 - 您应该使用括号明确设置 AND 和 OR 的优先顺序。
SELECT WEEK(start_time) AS Week, COUNT(1) AS Count
FROM offline_execution_jobs
WHERE start_time >= NOW() - INTERVAL 365 DAY
AND (application_name LIKE 'SPLAT-ROLLING'
OR application_name LIKE 'SPLAT' )
GROUP BY WEEK(start_time)
ORDER BY WEEK(start_time) ASC ;
这个查询:
SELECT WEEK(start_time) AS Week, COUNT(1) AS Count
FROM offline_execution_jobs
WHERE start_time >= NOW() - INTERVAL 365 DAY
AND (application_name LIKE 'SPLAT-ROLLING'
OR application_name LIKE 'SPLAT' )
GROUP BY WEEK(start_time)
ORDER BY WEEK(start_time) ASC ;
返回以下结果:
1 21
2 50
3 15
但是我需要这样的东西:
2011-01-04 08:05:24 21
2011-01-09 03:28:54 8
2011-01-16 06:08:18 11
2011-01-23 06:06:50 32
当我从 MySqlYog(MySql windows 客户端)执行这个查询时,我得到了想要的结果,当我从 php 代码执行这个查询时出现了问题:
SELECT start_time AS WEEK, COUNT(1) AS COUNT
FROM offline_execution_jobs
WHERE start_time >= NOW() - INTERVAL 365 DAY
AND (application_name LIKE 'SPLAT-ROLLING'
OR application_name LIKE 'SPLAT' )
GROUP BY WEEK(start_time)
ORDER BY WEEK(start_time) ASC ;
这是我从 php 得到的错误:
Invalid query: 'nolio_db.offline_execution_jobs.start_time' isn't in GROUP BY
Whole query: SELECT start_time AS Date, COUNT(1) AS Count FROM offline_execution_jobs WHERE start_time >= NOW() - INTERVAL 250 DAY AND (application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT' ) GROUP BY WEEK(start_time) ORDER BY WEEK(start_time) ASC ;
这就是代码的样子:
$query = "SELECT start_time AS Date, COUNT(1) AS Count
FROM offline_execution_jobs
WHERE start_time >= NOW() - INTERVAL 250 DAY
AND (application_name LIKE 'SPLAT-ROLLING' OR application_name LIKE 'SPLAT' )
GROUP BY WEEK(start_time)
ORDER BY WEEK(start_time) ASC ;";
//echo "<br><br>$query<br><br>";
// Create connection to DB
$conn = mysql_connect($db_host, $db_user, $dp_pass);
if (!$conn)
{
echo "<br/>Can't connect: $db_host";
die('Could not connect: ' . mysql_error());
}
关于php - 执行查询时出现问题(不在 GROUP BY 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7418231/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file