I have a list as follows:
l = [0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,2,2,2]
I want to determine the length of a sequence of equal items, i.e for the given list I want the output to be:
[(0, 6), (1, 6), (0, 4), (2, 3)]
(or a similar format).
I thought about using a defaultdict but it counts the occurrences of each item and accumulates i...
Hello, I have a small question. I need to make a predicate that counts from a natural number to some other natural number. I have to implement a check too, that the second interval is bigger than the first one. However I got stuck during my way.
Here is my code (SWI-PROLOG)
count(O, _, O).
count(A, B, C) :- count(A, B, D), C is D+1, C ...
Hi,
anyone know how can i do counting if in SQL alchemy like
COUN(IF(table_row = 1 AND table_row2 =2),1,0)
i make something like this,
func.COUNT(func.IF((TransactionMessage.tm_read==0 and TransactionMessage.tm_type==1),1,0)).label('t_message_count'),
But sqlalchemy make 2 seperate if with TransactionMesssage.tm_read,
and Transa...
I'd like to select posts that have one or more comments using Rails 3 and a single query.
I'm trying something like this:
Post.includes(:comments).where('count(comments.id)>0')
However I get this error:
ActiveRecord::StatementInvalid: PGError: ERROR: aggregates not allowed in WHERE clause
I've googled this and similar approaches,...
I am doing some standard paging in my application, returning 20 rows from the database at a time using PostgreSQL's standard OFFSET and LIMIT keywords. For instance, to get page 1:
SELECT stuff FROM table WHERE condition ORDER BY stuff OFFSET 0 LIMIT 20
It is a requirement of the application that we also show to the user the total nu...
My system consists of two user types - Students and Tutors.
- Tutors can create classes and packs
- Both Students and tutors can purchase classes and packs
Following are the tables involved
Groups
Users- Contains common fields of both user types
Tutor_Details- Tutor specific fields
WebClasses - Classes created by tutors
Learning_...
Struggling getting a query to work……..
I have two tables:-
tbl.candidates:
candidate_id
agency_business_unit_id
tbl.candidate_employment_tracker
candidate_id
The candidate employment can have duplicate records of a candidate_id as it contains records on their working history for different clients.
The candidates tables is unique f...
I've got a question in my test:
What is wrong with program that counts number of lines and words in file?
open F, $ARGV[0] || die $!;
my @lines = <F>;
my @words = map {split /\s/} @lines;
printf "%8d %8d\n", scalar(@lines), scalar(@words);
close(F);
My conjectures are:
If file does not exist, program won't tell us about that.
...
I've been stuck for quite a while now trying to get this query to work.
Here's the setup:
I have a [Notes] table that contains a nonunique (Number) column and a nonunique (Result) column. I'm looking to create a SELECT statement that will display each distinct (Number) value where the count of the {(Number), (Result)} tuple where Result...
I am trying to implement the following convenience method:
/**
* Counts the number of results of a search.
* @param criteria The criteria for the query.
* @return The number of results of the query.
*/
public <T> int findCountByCriteria(CriteriaQuery<?> criteria);
In Hibernate, this is done by
criteria.setProjection(Projections....
I'm pretty new to iPhone programming, so I'm looking for any pointers (no pun intended), links, search terms, etc. on how to make a very simple app that counts how many times one finger touches the screen and how long between each tap.
Thanks for any help, I know this resembles a lame question seeing as how I have really accomplished an...
Hi Everyone?
I have a Rails simple application that has two main models. A person model and a gift model. Gifts belong to people, and people have many gifts.
I am currently (in the people index view) listing all people in the database with the following code:
<% for person in @people %>
<li><%= link_to h(person.name), person %></li>
<...
Hi all
I have an array of tags taken from a MySQL database. Obviously, these tags are strings and are stored in an array, with one element in the array storing each tag. TO build my tag cloud, I want to be able to count the occurrences of each tag to find the most common tag.
For example, if I have the table below...
tag1
tag1
hi
bye...
Hi
I am trying to create a report and am looking to pull out some information from a table 'contact'. I am trying to pull out the 'advisor' relating to the contact and a count of contacts who have that advisor based on a set of criteria. This is fine and works, however, I want to pull out a third column which is also a 'Count' based on ...
Hi all,
again I am stuck with counting something in MySQL. The database structure is far from SOers´d call optimal, but nevertheless I do not have an influence here and have to live with it. Probably that´s one of the reasons why I need help again to get some information out of it :)
Assume I have:
some_id (not the PK of the table, n...
I have the following linq expression that lets me join two tables, group them by a "DSCID", and then get a count of the grouped values:
var qryGeoApppendCount =
from a in append
join g in geo
on a.Field<string>("RNO")
equals g.Field<string>("RNO")
group g by g.Field<i...
Hi everyone,
I have been searching all over the web and I have no clue.
Suppose you have to build a dashboard in the admin area of your Rails app and you want to have the number of subscriptions per day.
Suppose that you are using SQLite3 for development, MySQL for production (pretty standard setup)
Basically, there are two options ...
i have a problem during count data use this query:
SELECT A.*,
COUNT( B.Serial_number ) AS Qty_insp,
CONCAT(ROUND(A.`Reject_qty`/ COUNT(B.Serial_number)*100, 2),'%') AS NG_Ratio
FROM oqc_defect A
LEFT JOIN inspection_report B ON A.Model = B.Model
AND A.Line = B.Line
GROUP BY A....
Hi,
Please bear with me as I am newbie in SSAS/MDX. I want DISTINCTCOUNT measure on ID column of my fact table but after filtering -1 i.e. unknown IDs. I like to slice/dice on it as well.
Here are my tables
DimStudent
----------------------------
ID Name
-1 Unknown
1 Joe
2 Tim
3 P...
This is my current query
SELECT DAYNAME(date_created) AS Day,
COUNT(*) AS my_count FROM sometable
WHERE (@date_created >= '2010-10-20 21:02:38' OR @date_created IS NULL)
AND (@date_created <= '2010-10-27 21:02:38' OR @date_created IS NULL)
GROUP BY DAY(date_created)
It only returns data for that day if the count exists.
I was muc...