having

… where count(col) > 1

时光毁灭记忆、已成空白 提交于 2019-12-01 13:46:00
问题 I have a table like this: +-----+-----+-------+ | id | fk | value | +-----+-----+-------+ | 0 | 1 | peter | | 1 | 1 | josh | | 3 | 2 | marc | | ... | ... | ... | I'd like now to get all entries which have more than one value. The expected result would be: +-----+-------+ | fk | count | +-----+-------+ | 1 | 2 | | ... | ... | I tried to achieve that like this: select fk, count(value) from table where count(value) > 1; But Oracle didn't like it. So I tried this... select * from ( select fk,

Can I paginate a custom query without overriding the default pagination?

末鹿安然 提交于 2019-12-01 12:38:16
In my CakePHP (1.2) app, I have two actions that both use pagination - index and search. In a previous question I learnt that, in order to apply a threshold score to search results, I need to use the HAVING MySQL keyword. Since CakePHP does not support this natively, I need to drop down to a custom query in order to accomplish this. All the guides I can find to custom query pagination involve overriding the paginate() and paginateCount() methods. Since I still want to be able to paginate normally on the index however, I don't want to change the normal pagination behaviour in the model. Is

Can I paginate a custom query without overriding the default pagination?

南楼画角 提交于 2019-12-01 10:05:38
问题 In my CakePHP (1.2) app, I have two actions that both use pagination - index and search. In a previous question I learnt that, in order to apply a threshold score to search results, I need to use the HAVING MySQL keyword. Since CakePHP does not support this natively, I need to drop down to a custom query in order to accomplish this. All the guides I can find to custom query pagination involve overriding the paginate() and paginateCount() methods. Since I still want to be able to paginate

DELETE FROM HAVING COUNT(*) in MySQL

眉间皱痕 提交于 2019-11-30 02:39:42
问题 Ok so there are couple posts here already on this and fewer still out on the web. I've literally tried every one of them and can not get anything to work. Hopefully someone here can take pity on me :) Here is the data I'm working with. I want to delete all these records. SELECT part_desc, count(*) as rec_num FROM ag_master GROUP BY part_desc HAVING COUNT(*) > 1000; +--------------------------------------+---------+ | part_desc | rec_num | +--------------------------------------+---------+ |

MySQL joins and COUNT(*) from another table

℡╲_俬逩灬. 提交于 2019-11-29 22:53:29
I have two tables: groups and group_members . The groups table contains all the information for each group, such as its ID, title, description, etc. In the group_members table, it lists all the members who are apart of each group like this: group_id | user_id 1 | 100 2 | 23 2 | 100 9 | 601 Basically, I want to list THREE groups on a page, and I only want to list groups which have MORE than four members. Inside the <?php while ?> loop, I then want to four members who are apart of that group. I'm having no trouble listing the groups, and listing the members in another internal loop, I just

Retrieving records fulfilling a condition using GROUP BY

那年仲夏 提交于 2019-11-29 18:49:02
问题 I'd like to only select the rows where the count is greater than 1 (in other words the duplicates) right now from a few thousand records I am mostly seeing 1s with a few 2s and 3s here and there SELECT count( * ) AS `Number` , GI . * FROM `GeneralInformation` AS GI GROUP BY `FirstName` , `Surname` how can I do this? 回答1: SELECT count( * ) AS `Number` , GI . * FROM `GeneralInformation` AS GI GROUP BY `FirstName` , `Surname` HAVING count(*)>1 回答2: Use the Having clause SELECT count( * ) AS

Using the 'case…when…then…else…end' construct in the 'having' clause in JPA criteria query

别来无恙 提交于 2019-11-29 11:51:11
The following criteria query calculates the average of rating of different groups of products. CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple>criteriaQuery=criteriaBuilder.createQuery(Tuple.class); Metamodel metamodel=entityManager.getMetamodel(); EntityType<Product>entityType=metamodel.entity(Product.class); Root<Product>root=criteriaQuery.from(entityType); SetJoin<Product, Rating> join = root.join(Product_.ratingSet, JoinType.LEFT); Expression<Number> quotExpression = criteriaBuilder.quot(criteriaBuilder.sum(join.get(Rating_.ratingNum)),

What is the correct way to do a HAVING in a MongoDB GROUP BY?

随声附和 提交于 2019-11-28 21:11:52
For what would be this query in SQL (to find duplicates): SELECT userId, name FROM col GROUP BY userId, name HAVING COUNT(*)>1 I performed this simple query in MongoDB: res = db.col.group({key:{userId:true,name:true}, reduce: function(obj,prev) {prev.count++;}, initial: {count:0}}) I've added a simple Javascript loop to go over the result set, and performed a filter to find all the fields with a count > 1 there, like so: for (i in res) {if (res[i].count>1) printjson(res[i])}; Is there a better way to do this other than using javascript code in the client? If this is the best/simplest way, say

MySQL joins and COUNT(*) from another table

瘦欲@ 提交于 2019-11-28 19:43:57
问题 I have two tables: groups and group_members . The groups table contains all the information for each group, such as its ID, title, description, etc. In the group_members table, it lists all the members who are apart of each group like this: group_id | user_id 1 | 100 2 | 23 2 | 100 9 | 601 Basically, I want to list THREE groups on a page, and I only want to list groups which have MORE than four members. Inside the <?php while ?> loop, I then want to four members who are apart of that group. I

Hibernate Criteria API - HAVING clause work arounds

只愿长相守 提交于 2019-11-28 11:11:10
I've written a query using Hibernate Criteria API to grab a summation of a particular value, now I need to be able to restrict the result to rows where that sum is greater or equal to a particular value. Normally I would use a HAVING clause in my SQL to do this, but the Criteria API doesn't seem to support that at this moment. In raw SQL this is what I need it to do: SELECT user_pk, sum(amount) as amountSum FROM transaction GROUP BY user_pk HAVING amountSum >=50; One work-around that I thought of is to use a subquery in the FROM clause that grabs this summation value and use an outer query to