比较 Drupal 中的 2 个字段
我想在 Drupal 中执行一个简单的 SQL 查询,但我不知道如何执行。我想实现这一目标:
SELECT COUNT(nid) AS i_count FROM node WHERE `created` != `changed`;
我有以下代码,但不起作用:
$query = db_select('node', 'n');
$query->addExpression("COUNT(nid)","i_count");
$query->condition("created","changed","!=");
$i_number_published = $query->execute()->fetchCol();
它不起作用的原因是它将列 created
与字符串值 "changed 进行比较“
。有什么方法可以告诉它比较列而不是列字符串?
I want to do a simple SQL query in Drupal, but I'm not sure how. I would like to achieve this:
SELECT COUNT(nid) AS i_count FROM node WHERE `created` != `changed`;
I have the following code, which doesn't work:
$query = db_select('node', 'n');
$query->addExpression("COUNT(nid)","i_count");
$query->condition("created","changed","!=");
$i_number_published = $query->execute()->fetchCol();
The reason why it doesn't work is that it compares the column created
with the string value "changed"
. Is there any way I can tell it to compare columns instead of column-string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
where()
成员函数根据表中的其他字段添加条件:Use the
where()
member function to add conditions based on other fields in the table: