w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Adding and retrieving sorted counts in Cassandra
Outside of Cassandra I would recommend using stream-summary or count min sketch you would be able to solve this with much less space and have immediate results. Just update and periodically serialize and persist it (assuming you don't need guaranteed accuracy) In Cassandra you can keep a row per period of time like by hours and have a counter per user in that row, incrementing them on use. Then use a batch job to run through them and find the heavy hitters. You would be constrained to having the minimal queryable time be 1 hour and it wont be particularly cheap or fast to compute but it would work. Generally it would be good treating these as a log of operation, every time there is an event store it and have batch jobs do analytics against it with hadoop or custom. If need it realt

Categories : Cassandra

Aggregate SQL group by counts based on group by
Try switching the Order of the conditions in your CASE statement. SELECT (CASE WHEN str LIKE '%some_string2%' THEN 's2' WHEN str LIKE '%some_string%' THEN 's' END) as str, COUNT(*) as num FROM Table WHERE str LIKE '%some_string%' or str LIKE '%some_string2%' group by str

Categories : SQL

group number of counts by category
You should do: import collections counts = collections.defaultdict(lambda: 0) for fileid in corpus.fileids(): for sentence in corpus.sents(fileid): cat = str(fileid.split('/')[0]) s = " ".join(sentence) counts[cat] += len(re.findall('(:)|:(|:s|:D|:o|:@)+', s))

Categories : Python

Limit SQL query to only the top two counts per group
SELECT State, flv, total FROM (SELECT ROW_NUMBER() OVER ( PARTITION BY state ORDER BY count(INITCAP(TRIM(flavor))) DESC ) RowNumber, State, INITCAP(TRIM(flavor)) flv, count(INITCAP(TRIM(flavor))) total FROM favorite_flavor GROUP BY state, INITCAP(TRIM(flavor)) ) dt WHERE RowNumber <= 2 ORDER BY state ASC, total DESC

Categories : SQL

LINQ group by with multiple counts
you should group by trackId only, if you want results by trackId... var query2 = query .Where(m => m.Source == "UserRef") .GroupBy(m => m.TrackId) .Select(g => new FullReferrer { Customer = g.Key, FullRefFalseCount = g.Count(x => !x.FullRef), FullRefTrueCount = g.Count(x => x.FullRef) });

Categories : C#

How to make multiple group counts in MySQL
This should be pretty straight forward, COUNT() allows DISTINCT keyword to count only unique values. SELECT email, COUNT(*) email_count, COUNT(DISTINCT campaign) Unique_count FROM tableName GROUP BY email SQLFiddle Demo

Categories : Mysql

Select rows based on group by counts
To get the number of full siblings, you need to specify two keys to group by: var c = studentsDT .GroupBy(a => new { a.FatherID, a.MotherID }) .Where(g => g.Count() <= fullSiblings) .SelectMany(g => g) .GroupBy(a => a.FatherID) .Where(g => g.Count() <= halfSiblings) .SelectMany(g => g); Note that this counts a full sibling as a half sibling (i.e. it ensures that the total number of full and half siblings is less than halfSiblings).

Categories : C#

Multiple Counts using single MONGODB group query
if (doc.interaction.twitter.mention_ids == $twitter_id) { prev.mentions++; } Assuming mention_ids is an array in this example, I can't imagine how this condition returns true if "the first value in array is matched". You're comparing an array to a string value (I assume that's what $twitter_id is). To search the mention_ids array in JavaScript, you could either iterate through it and compare values (ideally break-ing out of the iteration after the first match), or utilize the Array.indexOf() method. As a rule of thumb, MDN's JavaScript portal is an excellent reference. In addition to the core JavaScript API, you can find a list of other JavaScript functions at your disposal in map/reduce functions in the mapReduce command docs.

Categories : PHP

Nested SQL Queries: How to get mutiple counts on same elements based on different criterias
Something like that should works for you: SELECT ( COUNT(id) FROM table WHERE id > 1 ) AS id_gt_1, ( COUNT(id) FROM table WHERE id > 100 ) AS id_gt_100 Here, the criteria I have matched is simply the count for the ID number.

Categories : SQL

How to group in ranges a sorted array of integers in Bash
I don't know of any standard ways of doing it, but it shouldn't be that hard to write your own function to do it. Something in the lines of: Save the first array elements 'value' as 'low' Iterate over the array and save current 'index' as 'high' When array 'value' differs from 'index', print out 'low-high' IF not 'low == high', then print 'low' Reset 'low' and 'index' to current 'value' and continue Increase 'index' by one Should be simple enough pseudo for a pre-sorted non-empty integer array :) (Sorry about formatting, I'm currently on a Mac with a PC keyboard and I don't get along with it very well.)

Categories : Bash

How to generate a radio group with a sorted data source?
<s:sort comparator="varDataComparator" source="#var.varDatas" var="datas"> <s:set var="temp"></s:set> <s:radio list="#temp" listKey="value" listValue="value" id="vardataId" name="%{#var.varId}"/> </s:sort>

Categories : Java

counts days inbetween then add class to those days with nested divs?
You mean something like this? $(function(){ var $class1 = $('.class1'); var $class2 = $('.class2'); var $afterClass1 = $class1.nextAll('.test'); var $beforeClass2 = $class2.prevAll('.test'); var count = $afterClass1.length + $beforeClass2.length; $('.count').html(count); }); http://jsfiddle.net/SAsty/ Edit: Better visualization http://jsfiddle.net/SAsty/3/ Edit 2: Do something like: var $allBetween = $afterClass1.add($beforeClass2); $allBetween.addClass('between');

Categories : Javascript

What is the implication of "A g-sorted array remains g-sorted even after h-sorting it"?
From what I was able to find, I think it means, that if array is Shell sorted with step G, it will remain sorted with step G after sorting with step H. It's important relation between G and H, I guess it is true for H < G, but don't take it for granted. But it's hard to guess what it might mean, without access to original text.

Categories : Algorithm

Getting N sorted items from an array of sorted arrays
According to your description of the problem, some solutions I can think of are : Ofcourse the one you suggested, i.e. appending all the arrays and then sorting them and taking first 20 of them. Sort each of these inner arrays individually and then do a merge like procedure from merge-sort algorithm to merge first 20 items from all these inner arrays and break out of the merge loop whenever desired number of items are merged(e.g. 20 items). Sort each of these inner arrays while putting dates in them. So that you won't have to iterate through each one afterwords. Then do a merge like procedure as said above. If you have several items in several inner arrays and you want first 20 out of them then you are going to have to iterate through the inner arrays to sort in some way or another. Th

Categories : Java

SQL nested select in group by
You need to use aliases because you have two references to the testing table: SELECT Department AS '@Department', ( SELECT Name FROM testing t2 WHERE t2.Department = t.Department FOR XML PATH ('Person'), TYPE ) FROM testing t GROUP BY Department FOR XML PATH ('Department'), TYPE Your query had Department = Department. These both refer to the inner testing, so they just choose the non-NULL values of Department.

Categories : SQL

Nested group query in Rails
As @tadman says, the result you're seeing is all the query can get you. If you want a custom format, you'll need to run it through an algorithm. Something like this should work for you: result = Answer.where(:question_id => 14).group(:club_id, :choice_id).count better_result = result.each_with_object({}) do |((club_id, choice_id), answers_count), m| m[club_id] ||= {} m[club_id][choice_id] = answers_count end

Categories : Ruby On Rails

SQL Select Statement with nested group by clause
SELECT v.vendor_name, i.totalbalance FROM Vendors as v INNER JOIN ( SELECT vendor_id, sum(invoice_total-payment_total) as totalbalance FROM invoices GROUP BY vendor_id ) as i on i.vendor_id = v.vendor_id

Categories : SQL

Rails - how to join/group nested tables and get joined values out?
You can make this little bit more prettier than raw sql by using rails AR querying methods: AccountGroup. select("account_groups.id, SUM(net_position), account_groups.name"). joins("LEFT JOIN accounts ON accounts.account_group_id = account_groups.id"). joins("LEFT JOIN positions ON positions.account_id = accounts.id"). group("account_groups.id,account_groups.name")

Categories : Ruby On Rails

Input-group controls resize within nested rows in IE9 and Twitter Bootstrap 3
I found out that the problem is in css line 9: .input-group .form-control { margin-bottom: 0; width: 100%; } I couldn't understand exactly the source of the problem but a simple workaround could be to add display:block !important;

Categories : Twitter

Given a sorted array, can we build a sorted array of the sums of all pairs in O(n^2)?
This is an open problem known in the literature as Sorting X + Y. The best result known is an O(n^2 log n)-time algorithm that uses O(n^2) comparisons, due to Lambert and Steiger--Streinu.

Categories : Algorithm

Generate a sorted key for a sorted value
Could this be described as "In this problem, out goal is to maintain a linked list with an explicit label for each node such that the labels are monotonic throughout the list, subject to inserting and deleting at any given location."? This is section 3 of http://courses.csail.mit.edu/6.897/spring05/lec/lec24.pdf. They show how you can maintain a table of keys in sorted order, with gaps, by viewing it as an implicit tree structure, in which reorganizing the keys within a section of table is equivalent to re-balancing a subtree.

Categories : Algorithm

Group a list of list by nested size in R
To get all nested list of length equal to 1 you can do the following: P3[lapply(P3,length) ==1] ## get all elements with size equal to 1 $`2` [1] "a" $`3` [1] "b" $`5` [1] "c" Now, We can use this to group the nested lists by their lengths. We loop(lapply) over all unique lengths, and we perform the above statement for each length : lapply(unique(unlist(lapply(P3,length))), function(x) P3[lapply(P3,length) ==x] )

Categories : R

Select ID from GROUP BY group if the group satisfied criteria
you should check beluw link http://www.w3schools.com/sql/sql_where.asp should use where caluse like 'where shipping_date = null '

Categories : SQL

Struts 1.1 nested and in combination
Use <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> and the code will look like <c:choose> <c:when test="${element.method1 == true}"> <c:choose> <c:when test="${element.method2 == true}"> <span style="color:green;"><c:out value="${element.prop1}/></span> </c:when> <c:otherwise> <span style="color:red;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose> </c:when> <c:otherwise> <span style="color:black;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose>

Categories : Java

Difference between two COUNTS
You would be wise to add to your select list any column(s) over which you group the results: SELECT sender, COUNT(*) AS s_count FROM pm WHERE userid = ? GROUP BY sender SELECT userid, COUNT(*) AS u_count FROM pm WHERE sender = ? GROUP BY userid You will then see that the first query returns the number of messages with the given userid, broken down by sender; whereas the second query returns the number of messages with the given sender, broken down by userid. As such, it doesn't make much sense to combine these queries "and get the difference out of it".

Categories : PHP

Different value counts on same column
This is a very basic "group by" query. If you search for that you will find plenty of documentation on how it is used. For your specific case, you want: select item_category, item_status, count(*) from <your table> group by item_category, item_status; You'll get something like this: item_category item_status count(*) ====================================== Chair under_repair 7 Chair condemned 16 Table under_repair 3 Change the column ordering as needed for your purpose

Categories : SQL

Rolling Distinct Counts
One possible way to model this in map reduce: M/R Job 1: Mapper: extract and output the USER_ID (output key) and date portion from the CONNECT_TS (output value). Reducer: For each USER_ID group (output key), output the minimum date observed (output value) M/R Job 2: Mapper: from the previous job output, swap the key / value pairs (DATE as output key, USER_ID as value) Reducer (single): for each input key (date), count the number of users (value), output this number along with an accumulated running total. In Pig, everything except keeping the running total could be done using the following script: A = LOAD '/home/cswhite/data.tsv' USING PigStorage(' ') AS (SESSION, USER_ID, TIMESTAMP); B = foreach A GENERATE USER_ID, SUBSTRING(TIMESTAMP, 0, 10) AS DATE; BF = filter B by DATE >

Categories : Hadoop

update row counts in a table
relname is misquoted in your function, but you don't need EXECUTE anyway, it's simpler to do: UPDATE row_counts set reltuples=$1 where relname=$2 If you don't like $1 and $2 you may use the function parameter names, but in this case don't name them the same as the columns. See Declaring Function Parameters in the doc. Also the empty DECLARE section is not needed.

Categories : SQL

Selecting counts of a substring
The DISTINCT and GROUP BY are redundant, you just want GROUP BY, and you want to GROUP BY the same thing you are selecting: select substr(custcode,2,5), count (*) from a group by substr(custcode,2,5) In SQL Server you can use column aliases/numbers in the ORDER BY clause, but not in GROUP BY. Ie. ORDER BY 1 will order by the first selected column, but many consider it bad practice to use column indexes, using aliases/column names is clearer.

Categories : SQL

Duplicate Counts - TSQL
Well, I have this solution, but using a Count... SELECT T1.*, ROW_NUMBER() OVER (PARTITION BY T1.ID, T1.Descp ORDER BY (SELECT 0)) AS DuplicateRowNumber, CASE WHEN T2.C = 1 THEN 0 ELSE 1 END MultipleOcurrences FROM #temp T1 INNER JOIN (SELECT ID, Descp, COUNT(1) C FROM #TEMP GROUP BY ID, Descp) T2 ON T1.ID = T2.ID AND T1.Descp = T2.Descp

Categories : SQL

Urllib Counts as WebPage Hit?
both do very different things. using urllib.request.urlopen makes a single http request. your second example will do the same, and then it will parse the document it receives and request subsequent resources (images/javascript/css/whatever). So the result of loading google.com in your browser will trigger many hits. try it yourself by looking in your browsers development tools (usually in network section) while you load a page.

Categories : Python

How can I get several counts of a column in one SQL query?
Use SUM instead of COUNT: SELECT o.first_name, o.last_name, SUM(CASE WHEN p.type = 'cat' THEN 1 ELSE 0 END) as cat_count, SUM(CASE WHEN p.type = 'dog' THEN 1 ELSE 0 END) as dog_count, SUM(CASE WHEN p.type = 'fish' THEN 1 ELSE 0 END) as fish_count FROM PetOwners o JOIN Pets p ON o.id = p.owner_id GROUP BY o.id And if you want to include owners that don't have any pets at all, change JOIN to LEFT JOIN.

Categories : Mysql

how to repeat code for certain counts?
You could increment a counter in each execution of MyTimerTask.run(). Then when this counter equals the amount of times you want it to show the Toast notification, you can cancel the TimerTask with myTimer.cancel();.

Categories : Android

Sum of all counts in a collections.Counter
Sum the values: sum(some_counter.values()) Demo: >>> from collections import Counter >>> c = Counter([1,2,3,4,5,1,2,1,6]) >>> sum(c.values()) 9

Categories : Python

sum column counts for two different values
Yes, a case statement will work for this: select (case when mycol in ('1', 'var1') then 'var1' when mycol in ('2', 'var2') then 'var2' when mycol in ('3', 'var3') then 'var3' end), sum(ttl) as Total from mytable t group by (case when mycol in ('1', 'var1') then 'var1' when mycol in ('2', 'var2') then 'var2' when mycol in ('3', 'var3') then 'var3' end); EDIT: If you just have the data with multiple rows for each value: select (case when mycol in ('1', 'var1') then 'var1' when mycol in ('2', 'var2') then 'var2' when mycol in ('3', 'var3') then 'var3' end), count(*) as Total from mytable t group by (case when mycol in ('1', 'var1') then 'var1' when myco

Categories : Mysql

Two Counts in a MYSQL Query
Try like SELECT COUNT(*) as num1, COUNT (search_term) as num2 FROM $tableName WHERE client_id = '{$client_id}' AND search_term IS NOT NULL AND search_term != '' GROUP BY search_term LIMIT $page , $limit And you need to give $page value as the current page number and $limit will be the limit that one page contains

Categories : PHP

MySQL multiple COUNTs
I think this could be a typo anyway your are trying to sum your COUNT() times, simply replace with money_earned SELECT user_id, COUNT(*) AS 'times', SUM(money_earned) AS 'sum_money' FROM mytable GROUP BY user_id; SQL Fiddle

Categories : Mysql

combining records in counts
If spaces and periods are the only punctuation you want to ignore you can use: SELECT MAX(fld1), -- select one of the group's values. COUNT(*) FROM tbl1 GROUP BY REPLACE(REPLACE(fld1, ' ', '' ), '.', '')

Categories : SQL

SELECT with multiple COUNTs
You do it like this using SQL grouping, along with the COUNT() and SUM() aggregate functions. For SUM we use a standard SQL "trick" of an embedded CASE statement. select GRP, COUNT(*) as Total, SUM(CASE WHEN STATUS = 'Pass' THEN 1 ELSE 0 END) AS Pass, SUM(CASE WHEN STATUS = 'Fail' THEN 1 ELSE 0 END) AS Fail from table group by GRP Average Use the same tricks to get average knowing that the AVG aggregate will ignore any parameter which is null. select GRP, COUNT(*) as Total, SUM(CASE WHEN STATUS = 'Pass' THEN 1 ELSE 0 END) AS Pass, SUM(CASE WHEN STATUS = 'Fail' THEN 1 ELSE 0 END) AS Fail, AVG(CASE WHEN STATUS = 'Pass' THEN Score ELSE null END) AS PassAVG, AVG(CASE WHEN STATUS = 'Fail' THEN Score ELSE null END)

Categories : SQL

Integer that counts up and is divided by 60
First of all if you are 5 you shouldn't play with JavaScript. Apart from the joke, what you need is when the user hit the submit, you store the timestamp on the server side, since you mentioned in a n SQL table maybe, and on pageload you pass this values to your page (you can send it as a javascript array inside the HTML generated by the PHP, but I would rather go with asking all the data from the server separately using AJAX right after pageload to avoid fuzzy codes) and then just calcualting the difference between those timestamps and the current time and refreshing the cells with those values every second (or minute) using setInterval(). var exampleArray = [ ['user1', timestamp], ['user1', timestamp] ]; function count(){ var currentTime = new Date().getTime(); for(var i in exa

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.