简体   繁体   English

如何编辑此mySQL查询以不选择2列中具有相同值的行?

[英]How to edit this mySQL query to not select rows that have same value in 2 columns?

Running the following query I get the following message 运行以下查询我收到以下消息

invalid use of group by 无效使用group by

SELECT COUNT( id ) AS pages,
       hash, MIN( DATE( TIMESTAMP ) ) AS FirstVisit, 
       MAX( DATE( TIMESTAMP ) ) AS LastVisit
       FROM behaviour
       WHERE MIN( DATE( TIMESTAMP ) ) != MAX( DATE( TIMESTAMP ) )
       GROUP BY hash

How can I edit this query so as to not show the rows that FirstVisit equals LastVisit ? 如何编辑此查询以便不显示FirstVisit等于LastVisit的行?

Aggregate function can't be used in where clause, but can be used in having`. 聚合函数can't be used in where clause, but can be used in have`中使用。

Try this: 尝试这个:

SELECT
     COUNT( id ) AS pages,
     hash,
     MIN( DATE( TIMESTAMP ) ) AS FirstVisit,
     MAX( DATE( TIMESTAMP ) ) AS LastVisit
FROM behaviour 
GROUP BY hash
HAVING MIN( DATE( TIMESTAMP ) ) != MAX( DATE( TIMESTAMP ) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mysql选择行两列不具有相同值 - Mysql Select Rows Where two columns do not have the same value 如何选择内容相同但列不同的MySQL行? - How to select MySQL rows that have the same content but in different columns? 如何识别mysql中相同列中具有相同值的行? 而且我还必须向这些行添加条件 - How to identify rows that have the same value in same columns in mysql? and also i have to add condition to those rows 如何使用SQL / mySQL选择2列具有相同值的多个且1列具有不同值的行? - How do I use SQL/mySQL to select rows where 2 columns have multiple of the same value and 1 column has a distinct value? MySQL Query:如何选择没有特定值的行? - MySQL Query: How to select rows that don't have a certain value? 如何查询具有第v.2列之一相同值的行中具有最高列值的行 - How to query for rows that have highest column value among rows that have same value for one of the columns v.2 SQL - 选择在两列中具有相同值的行 - SQL - select rows that have the same value in two columns mysql选择两列中具有相同值的所有行 - mysql select all rows with same value in two columns mysql选择与上次输入的行具有相同值的行 - mysql select rows that have a same value as the last entered row mysql从id中选择所有具有相同值的行 - mysql select all rows that have same value from id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM