count

Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?

I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count? (I've defined an __eq__ to define uniqueness on my object definition). So in RDBMS-land, something like this: CREATE TABLE x(n NUMBER(1)); INSERT INTO x VALUES(1...

How can i count this variables in my DB?

Hello Colud you please help me about this problem ? I have 4 variables XTSM is between 0~200 XTS is between 0~2 XRX is 0~3 XHAN is 0~7 ZHTYPE is one of these : (1)TCHF_HLF (2)TCHSD (3)TCHFULL they are related to their with this shape . XTSM->XTS->XRX->XHAN->ZHTYPE (Just Logical) this means : Each XTSM has 3 XTS (0-2) Each X...

NHibernate : Count childrens' children

I have an entity type A. Which has many B's. The B entity has many C's. I need to count how many C's does an A entity have. How can this be done using NHibernate Criteria API? Using LINQ to NHibernate I was unable to get results since it throws an exception (see this question) ...

Words stats in a Text with Delphi

Hi I'm using Delphi 7. I would like to count the number of repetitions of every word in a large text (500 words). How could I do it? ...

HQL query throws ClassCastException when using count()devided by double value

I have a query looks like this @NamedQuery(name="WorkingDayLog.getExpectedWorkingHours",query="select ((count(o.id)-:approvedVacs)*(:shiftDuration/60.0)*:factor) from WorkingDayLog o where o.workingDayDate between :appraisalStart and :appraisalEnd")` it compiles fine but when executed it throws the following exception ClassCastExce...

MySQL - How do I get SUM of a COUNT of a field?

I'm using the following statement and getting almost everything I need. In addition, I'd like to get the SUM of all of the row_total results. SELECT c.id AS campaign_id, c.amount AS campaign_amount, c.warning_trigger, COUNT(cc.id) as code_count, DATEDIFF(c.end_date, CURDATE()) as days_remain, SUM(c.amount) as row_total FROM campaign...

PHP SQL counting number of matches for query

How would i go about counting the number of rows that match two variables? I have a table called: users and fields called: username & referral I have another table called: comments and fields called: *comment_username* This is the situation, I need to fetch the number of referrals with at least 10 comments (rows in the comments' tab...

In which cases are IEnumerable<T>.Count optimized?

Using reflector I have noticed that System.Linq.Enumerable.Count method has a condition in it to optimize it for the case when the IEnumerable<T> passed is in fact an ICollection<T>. If the cast succeeds the Count method does not need to iterate over every element, but can call the Count method of ICollection. Based on this I was starti...

MySQL - Counting rows and left join problem

I have 2 tables, campaigns and campaign_codes: campaigns: id, partner_id, status campaign_codes: id, code, status I want to get a count of all campaign_codes for all campaigns WHERE campaign_codes.status equals 0 OR where there are no campaign_codes records for a campaign. I have the following SQL, but of course the WHERE statement e...

MySQL Query Issue - Count Query Uses lot of CPU

Hi, We have a table on mysql to log all visitors of our site. The structure is shown below CREATE TABLE `tblvisitors` ( `visitorURL` longtext, `visitorDatetime` datetime DEFAULT NULL, `visitorIP` varchar(255) DEFAULT NULL, `visitorID` int(10) NOT NULL AUTO_INCREMENT, `visitorUser` varchar(255) DEFAUL...

Select Count(Distinct Value) returns 1

I'm designing a query in SSMS 2005 which looks something like this: SELECT COUNT(DISTINCT ColumnName) FROM Table WHERE ColumnName IS NOT NULL When I run the query with COUNT() it returns the value 1. When I run it without COUNT(), SSMS reports the correct value eg 212 records. The column in question is of datatype numeric(16, 0). Fo...

SQL If "something" select count

The output that comes from a custom view of mine is as follows... Col1 Col2 Col3 Col4 xxxx Cake 1 1* Cake xxxx 2* 1 xxxx Cake 2 0* xxxx Cake 0 0* Cake xxxx 2* 0 Cake xxxx 2* 0 and what i would like to sum is... For every row, if the word Cake is found in Col1, t...

Counting the Number of keywords in a dictionary in python

I have a list of words in a dictionary with the value = the repetition of the keyword but I only want a list of distinct words so i wanted to count the number of keywords. Is there a to count the number of keywords or is there another way I should look for distinct words? ...

SQL query to count total amount of time

Hello, I have a column in a SQL table that is the times that measurements were made. As shown in Table1 below, the measurement times can be out of sequence, repeated, or irregularly sampled (they are generally but not always 100 milliseconds apart). When the time stamp is missing (like 2009-12-20 11:59:56.1 in the example below), that...

Counting elements in a tree in Haskell

Hi Basically I've made a polymorphic tree data type and I need a way of counting the number of elements in a given tree. Here's the declaration for my Tree data type: data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) deriving (Eq, Ord, Show) So I can define a tree of Ints like this: t :: Tree Int t = Node (Leaf 5) 7 (Node (Lea...

Count(*) vs Count(Id) in sql server 2005

I use Count function to get the total number or rows from a table... Is there any difference between the two following statements? Select Count(*) from Table and select Count(Id) from Table Is there a difference between execution times... ...

Problem in sorting xml in XSLT 2.0 any ideas?

Hello I am trying to sort my xml by number of occurence of element 'answer' with attribute 'id' and get simply summary. <person id="1"> <answer id="A"/> <answer id="B"/> </person> <person id="2"> <answer id="A"/> <answer id="C"/> </person> <person id="3"> <answer id="C"/> </person> I want simply summary text on output: A = 2...

Why does NSMutableArray Count crash my app?

I've ran into a problem. Everytime I'am starting my app it crashes. Heres me code. The Debugger Says: [list count] crashes the app. I have no idea. NSLog(@"%@", self.list); gives me one item as expected... if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { data = [[NSData alloc] initWithContentsOfFile:filePath]; unarc...

MySQL AVG(COUNT(*) - Orders By day of week query?

This query has baffled me... I've searched the web work over a day now and I have tried numerous things. I want to get the avg number of orders for every day of the week from my db. I can pull the total # with COUNT just fine. But I just can't figure out how to get the AVG of COUNT on a GROUP BY. I've tried subqueries... functions... ev...

Sort mysql table based on number of rows in another table

Hi, I'm trying to sort a user table based on how many comments they have linked to them in a secondary comment-table, I figured a sub-select will be the best tool but I can't get the syntax correct. Users table testdata: id | user_id 1 | 1000 2 | 1001 3 | 1002 Comment table testdata id | link_id 1 | 1002 2 | 1000 3 | 1002 4 |...