count

Please will you help tune a 7-table-join mysql count query where tables contain 30,000+ rows?

I have an sql query that counts the number of results for a complex query. The actual select query is very fast when limiting to 20 results, but the count version takes about 4.5 seconds on my current tables after lots of optimizing. If I remove the two joins and where clauses on site tags and gallery tags, the query performs at 1.5 sec...

Optimize an SQL query to get count of specific answers

I'm creating a survey with 10 questions. All questions have 5 possible answers with values from 1-5. The data is stored in a database with one row per user. There is a column for the answer to every question. To make bar graphs for the answers to every question, I currently retrieve the count of rows where the value of a specific colu...

How do I get a list of unique values and the number of occurences from SQL Server 2008?

I have a SQL Server 2008 database with millions of records. One field has values ranging from 0 to 250 and may, or may not, include all numbers witin the range. How do I query the database to get a list of distinct values and the number of records contaiing that value? I used a Select Count(Distinct) query but that only gives me the num...

How to count inverse with for in php?

PROBLEM RESOLVED My Problem: I want to count inverse in the for loop. This is the opposite of what I want to do: for($i=1;$i<=10;$i++){ echo $i; } If I put $i-- doesn't works (my server crashes). Help meeee! Best Regards, Adam ...

Progressive count using a query ?

I use this query to SELECT userId, submDate, COUNT(submId) AS nSubms FROM submissions GROUP BY userId, submDate ORDER BY userId, submDate obtain the total number of submissions per user per date. However I need to have the progressive count for every user so I can see how their submissions accumulate over time. Is this possible to i...

Complicated SQL query - Finding a set of something, counting it, then finding a subset of the first set, and counting that

I have three tables, we'll call them table1, table2, and table3. Lets say each table has a user id column and a date column. What i'd like to do is to be able to count the number of rows with a specific user id in table1, and sum it with the number of rows with that user id in tables 2 and 3. I'd then like to take that first query I d...

SQL how to count all rows up to a max value

I am having trouble counting the number of rows until it reaches a certain PK. My PK is called id and I want to count all rows until i reach a specified id I have tried using this query but it doesn't work probably becuase I am using a MySQL table select max(count(*)) from news where id=18 group by id I get this error Invalid us...

SQL using count value as offset

This is a follow on from another question i made I have this query that counts all the records up to a certain point i choose whcih works fine SELECT count(*)FROM news WHERE id < 18 this query gives me a count of 7 I am now having problems with the offset which would be the result of the above query I tried using this query SELECT...

How to use COUNT() with MYSQLi and Prepared Statements?

Hi, I need to count the number of persons with the same status from a table for a specific user.. I want to use prepared statements so I did something like this (not working): $sql = 'SELECT status, COUNT(personID) FROM user_persons GROUP BY status WHERE userID = ?'; if ($stmt->prepare($sql)) { $stmt->bind_param('i', $userID); ...

Array not populating correctly

Hi I am using the following code to populate an array: $number = count ($quantitys); $count = "0"; while ($count < $number) { $ref[$count] = postcodeUnknown ($prefix, $postcodes[$count]); $count = $count +1; } postcodeUnknown returns the first row from a mysql query, using a table prefix and an element ...

Zend Framework: count() returns 1 on empty result with findManyToManyRowset(...)

Hi :) While working on a small shop application i fetch all colors of an article using Zend Framework's "findManyToManyRowset" functionality. Example: $colors = $article->findManyToManyRowset('Shop_Colors', 'Shop_ArticlesToColors'); Some of the articles don't have and colors assigned. I test it using count($colors) on the ...

Nested Select Count Query with Criteria

Hi all, say that we have 2 entity EntityA and EntityB , with the related tables, TableA and TableB. i have to implement this query: select a.Id , (select count(b.Id) from TableB b where b.FKa = a.Id and b.AnotherField > 0) as TheCount from TableA a i'm very close to that since i wrote this code: var subCrit = DetachedCriteria.For<...

T-SQL Count rows with specific values (Multiple in one query)

Hi. I could need some help with a T-SQL query. I want to count fields, that have a special value(e.g. >1). Assuming i have a table Like IGrp | Item | Value1 | Value2 ############################# A | I11 | 0.52 | 1.18 A | I12 | 1.30 | 0.54 A | I21 | 0.49 | 2.37 B | I22 | 2.16 | 1.12 B | I31 | 1.50 | 0.28 ...

How to count records from multiple columns using sql and asp.net?

I have a table with 5 columns: ID, Session1, Session2, Session3, Session4. What I want to do is to display the number of same items from each column. Same item can't appear in more than one column. ID Session1 Session2 Session3 Session4 -- -------- -------- -------- -------- 1 Music Web Tech Fu...

Getting User Count From IRC

I am making IRC chat client and I am wanting to grab the user list or simply the user count, how can I go about doing this. This is the method I'm using to connect to the IRC: Private Sub IRCConnect() Dim stream As NetworkStream Dim irc As TcpClient Dim reader As StreamReader Try irc = New Tcp...

LINQ : Group by Multiple Columns and Count

I have Table1 and Table2 in the form of IEnumerable. Both the tables have columns Column1 and Column2 I would like to do a left outer join on Column1 and would like to get a count of the rows present in Table2 and load the records into a DataTable. I tried the following query var query = from p in Table1 join q in...

Getting allocation count plus one at UIImage in objective-c?

Hi Guys, I am getting allocation count plus one in the below code. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; if (cell == nil) { cell = [[[UITableVie...

List of elements

Hello, I have some links at the page like: 123test.com/456 abc_test.com/sdfsd abc_test.org I have to get all elements which href attribute consists of test word. I know how to click at such link by given number: selenium.click("//body/descendant::a[contains(@href,'test')][2]") This code will click at second link which has 'test' i...

Allow specific number of NSWindow copies to be visible

I have a button in my application, when you click it it opens a new NSWindow. However, if you keep on clicking it it will open another NSWindow. How can I limit the number of visible windows? ...

SQL: Group counts in individual result rows

When I run query number 1: SELECT id, name, COUNT(name) AS count FROM markers WHERE state like 'OR' group by named I get the following results: id name count 14 Alsea 2 76 Applegate Valley 1 3 Ashland 9 64 Beaver 1 26 Bend 1 10 Carlton ...