count

MySQL GROUP BY and COUNT

百般思念 提交于 2020-01-04 09:42:55
问题 I have a small problem regarding a count after grouping some elements from a mysql table, I have an orders table .. in which each order has several rows grouped by a code (named as codcomanda) ... I have to do a query which counts the number of orders per customer and lists only the name and number of orders. This is what i came up (this might be dumb ... i'm not a pro programmer) SELECT a.nume, a.tel, ( SELECT COUNT(*) AS `count` FROM ( SELECT id AS `lwtemp` FROM lw_comenzi_confirmate AS yt

Use count or have a field that tallies?

若如初见. 提交于 2020-01-04 07:38:31
问题 Fairly simple concept, making an extremely basic message board system and I want users to have a post count. Now I was debating on whether or not to have a tally in their row that is added each time a post by them is created, or subtracted by one each time a post of theirs is deleted. However I'm sure that performing a count query when the post count is requested would be more accurate due to unforseen circumstances (say a thread gets deleted and it doesn't lower their tally properly),

Use count or have a field that tallies?

强颜欢笑 提交于 2020-01-04 07:38:08
问题 Fairly simple concept, making an extremely basic message board system and I want users to have a post count. Now I was debating on whether or not to have a tally in their row that is added each time a post by them is created, or subtracted by one each time a post of theirs is deleted. However I'm sure that performing a count query when the post count is requested would be more accurate due to unforseen circumstances (say a thread gets deleted and it doesn't lower their tally properly),

MySQL COUNT function not performing as I would like in multiple joined query

不问归期 提交于 2020-01-04 07:31:06
问题 I have been altering a query for a while now, reading many posts on this wonderful site to get to where I am with this so far. But, alas, now I am stuck :( This query and relevant part of the database I have designed is similar to the youtube comment liking system. Relevant tables and fields are: USRS usr_id int (PK) COMMENTS comment_id int (PK) usr_id int (FK) references usrs(usr_id) topic_id int (FK) references topics(topic_id) descr varchar created varchar COMMENT_LIKERS comment_id int (PK

SQL keeping count of occurrences through a sliding window

[亡魂溺海] 提交于 2020-01-04 06:44:14
问题 In the previous question (Please refer to: SQL Keeping count of occurrences) I needed to count the number of occurrences of a variable. The code provided was as follows: SELECT [Date], Code, [Count] = COUNT(*) OVER (PARTITION BY Code ORDER BY [Date] ROWS UNBOUNDED PRECEDING) FROM dbo.YourTable ORDER BY [Date]; However, now I need to introduce an improvement to that code: Let's say that I have the following table: Date | Code ------------------------ 2010/01/01 | 25 2010/01/01 | 22 2010/01/01

Count occurrences of strings in Java

♀尐吖头ヾ 提交于 2020-01-04 06:20:30
问题 Is there a good class that can count the occurrences of specific strings in java? I'd like to keep a list of names and then create unique email addresses for each name. For each occurrence of a last name, I'd like to increment the associated number by one. Ex: If I have 3 people with the last name Smith, I'd like their address to be smith1@(Address), smith2@(Address), and smith3@(Address). I saw a class "Map" but I can't seem to initialize it correctly. Is there a class that I can use to keep

SQL - Counting a column twice

▼魔方 西西 提交于 2020-01-04 05:24:16
问题 I have a table that has a column called 'status'. This can be set to 0 or 1 Is it possible for me to count both the 0's and 1's in a single query? Thanks in advance James 回答1: Yes, just group on the value of status : SELECT status, COUNT(*) FROM yourtable GROUP BY status That will give you exactly two rows since the value can only be 0 or 1 , and the COUNT(*) column will be the number of times each status value appears in the table. 回答2: SELECT SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) AS

MYSQL Count all rows and pagination of data using range/limit

亡梦爱人 提交于 2020-01-04 03:16:30
问题 I dont know if this is a duplicate but here's my question.. I was trying to implement a pagination of data taken from database My dilemma is: Should i go about pagination, querying data in groups, ie. 5 (doing a Select with limits/ range), then displaying them in a table with pagination. It will have page numbers so it would require counting all the table entries thus that would be 2 database queries for the initial display.or query all the row entries and then count the result set and apply

PostgreSQL efficiency of count query, materialized views [duplicate]

落爺英雄遲暮 提交于 2020-01-04 02:47:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Optimization of count query for PostgreSQL Using PostgreSQL 9.2, we are trying to figure out if there is a way to keep track of the number of results for a query, and return that number in an efficient manner. This query should be executed several (possibly tens to hundreds or even thousands) of times per second. The query we have right now looks like this, but we wonder if this is inefficient: -- Get # of rows

MYSQL including values for dates with zero item counts

こ雲淡風輕ζ 提交于 2020-01-04 02:11:10
问题 I'd like to count the total number of purchases as well as the purchases by item_id over time. In this example, a user can own an item and these items can be purchased by other users. An owner can't purchase their own item. The problem I'm having is how to return results with counts of "0" for days where there were no purchases alongside the days with positive integer counts. Here's my tables: items | items_purchased | numbers | dates i_id item_id user_id | p_id item_id user_id date | num |