count

Selecting count of zero while grouping by column

I have a jobs table, and am trying to get a count of jobs for different time frames. My current query looks like this: SELECT COUNT(*) AS 'count', WEEK(j.created_at) AS 'week', MONTH(j.created_at) AS 'month', YEAR(j.created_at) AS 'year', DATE_FORMAT(j.created_at, '%y') AS 'short_year' FROM jobs j WHERE j...

MySQL include zero rows when using COUNT with GROUP BY

Hi, I am trying to perform a query which groups a set of data by an attribute called type_id. SELECT vt.id AS voucher_type, COALESCE(COUNT(v.id), 0) AS vouchers_remaining FROM vouchers v INNER JOIN voucher_types vt ON vt.id = v.type_id WHERE v.sold = 0 GROUP BY vt.id What I want in the result is the type_id and the number of unsold p...

oracle sql group count

SELECT a,b,count(*) FROM t GROUP BY rollup(a,b) result: a1, b1, 10 a1, b2, 90 a1, , 100 i need: a1, b1, 10, 100 a1, b2, 90, 100 how? ...

Using mysql COUNT(*)

Why is COUNT(*) so much quicker than COUNT(field), Even when field is an index? I am using MySQL ...

Calculate Distinct count when joining two tables.

id1 id2 year State Gender ==== ====== ====== ===== ======= 1 A 2008 ca M 1 B 2008 ca M 3 A 2009 ny F 3 A 2008 ny F 4 A 2009 tx F select state, gender, [year], count (distinct(cast(id1 as varchar(10)) + i...

Adding or merging python dictionaries without loss

I'm trying to count up ip addresses found in a log file on two servers and then merge the dictionary stats together without loosing elements or counts. I found a partial solution in another stack overflow question but as you can see it drops the '10.10.0.1':7 pair. >>> a = {'192.168.1.21':23,'127.0.0.1':5,'12.12.12.12':5,'55.55.55.55':1...

MySQL Left Outer Join with Count from joined table, Show all records

Hi All, i am trying to create a query where there is a count of related records from another table. I'd like the "parent" records whether there are related records (a count) or not. SELECT r.region_name, r.region_id, r.abbreviation, r.map_order, (IFNULL( COUNT( p.property_id ) , 0 )) AS propertyCount FROM `rmp_region` r LEFT OUTER ...

using jQuery to add and remove textbox with unique IDs

I wrote a function to add listitem with a text box and a remove button, everytime the add button was clicked. i'm also adding a unique id to each new element by adding a number. the problem happens when i try to remove an element, then add another one, sometimes that number is being duplicated. ex: I add 4 li's and decide to remove #3...

linq count with join on multiple tables

Let's say I have 3 tables: carts, baskets and eggs where a basket can contain many eggs and where carts contain many baskets. Each basket has a foreign key that maps to a cart and each egg has a foreign key that maps to a basket. I need to return a table that contains these columns: -Cart Name -Number of Baskets in Cart -Number of Eggs...

Script counting characters in a text box using Javascript not working?

I need to enforce character count limit in my application. I found some JavaScripts from web but they are not working, Here is my code. I would be very thankful if someone can kindly see the code & correct whats causing problem. <HTML> <HEAD> <script type="text/javascript" src="http://ajax.googleapis.com/ ajax/libs/jquery/1.4.2/jquery....

MySQL: count data from A month until B month

regarding to this question, i have a problem if use that query for count some data. How to make it can count data for ex. from 2010-01 until 2010-05? after use that query the show as null. this is my query: SELECT id, Line, COUNT( Serial_number ) AS Qty, SUM(S), SUM(A), SUM(B), SUM(C), (SUM( S ) + SUM( A ) + SUM( B ) * 0....

mysql count query

I have a mysql table set up like this id | refference_id | data Is it possible to count the number of entries for each refference_id all in the query ? ...

SQL field = other field minus an other ROW!

Table has 2 cols: [nr] and [diff] diff is empty (so far - need to fill) nr has numbers: 1 2 45 677 43523452 on the diff column i need to add the differences between pairs 1 | 0 2 | 1 45 | 43 677 | 632 43523452 | 43522775 so basically something like : update tbl set diff = @nr - @nrold where nr = @nr but i don't want...

Select all rows from SQL based upon existence of multiple rows (sequence numbers)

Let's say I have table data similar to the following: 123456 John Doe 1 Green 2001 234567 Jane Doe 1 Yellow 2001 234567 Jane Doe 2 Red 2001 345678 Jim Doe 1 Red 2001 What I am attempting to do is only isolate the records for Jane Doe based upon the fact that she has more than one row in this table. (More that one seque...

Java image analysis - counting vertical lines

Hello, I need a little help on an image analysis algorithm in Java. I basically have images like this: So, as you might guessed, I need to count the lines. What approach do you think would be best? Thanks, Smaug ...

SQL multiple join with count, having trouble.

Hello All, First of all this is a homework assignment so I'm looking for assistance, not solutions. Let me try to explain my schema. I have three tables we'll call users (with columns id and name), parties (with columns id, partydate, and user_id) and questions (with columns id, createdate, and user_id). My requirement is to show for e...

How to make HTML combo box save values added by user in textbox?

I have made a combobox for a web page. It takes values from user into text box & adds those to list on double click in text box. I want to make user entered values permanently stored as option in list. How can I do it. One more question is how can I count the number of options in list so that I add an element next to that. Here is my co...

Doing multiple MySQL counts in one query?

Hey guys..... now I know the below query isn't valid, but I'm just using it as an example as what I'm trying to achieve. Basically what I want to do is get a COUNT() of all the rows & then also get a COUNT() of rows with a condition clause in the one query. Such as.. SELECT COUNT(*) AS full_amount, COUNT(address IF NOT NULL),...

MySQL:set result two digits behind comma

i have some formula: CONCAT((SUM(X.lot_qty)-SUM(X.reject))/SUM(X.accept)*100,'%') AS Acceptance but i get result like: 100.0000% how to get result as 100.00%? ...

How to count string length of a domain list and group them by length?

I have a list of domain names, for example: domain1.com domain2.com domainxxx2.com dom.com from that list I want to get: length 7 [2] length 10 [1] length 3 [1] I know how to split the tld and count each domain length, but dont know how to group and count those with the same length. I would like to do it on PHP. ...