count

mysql count only for distinct values in joined query

流过昼夜 提交于 2020-01-05 12:34:43
问题 WOW! That's a weird title, but I'm happy you're looking, cause I couldn't find another way to say it. I have a table of people and a table of links to photos and videos. I join the people to the media, and of course a person can have more than one piece of media. I am attempting to grab the first 30 people and all of their media in one query, but when I say LIMIT 0,30. Of course I'll only get the first 30 media files, which could be 10 people. Before I make the query, I don't know how many

mysql count only for distinct values in joined query

南笙酒味 提交于 2020-01-05 12:34:13
问题 WOW! That's a weird title, but I'm happy you're looking, cause I couldn't find another way to say it. I have a table of people and a table of links to photos and videos. I join the people to the media, and of course a person can have more than one piece of media. I am attempting to grab the first 30 people and all of their media in one query, but when I say LIMIT 0,30. Of course I'll only get the first 30 media files, which could be 10 people. Before I make the query, I don't know how many

How to count characters in a string? (python)

我是研究僧i 提交于 2020-01-05 12:10:49
问题 # -*- coding:UTF-8 -*- str= "Green tree" scr= "e" cstr= len(str) n=0 a=0 while n < cstr: if str[n] == scr: print(len(scr)) n=n+1 I have to count "e" in -str- string, but when I run this script I get 1 1 1 1 instead of 4. What's the problem? 回答1: First of all, don't use str as a variable name, it will mask the built-in name. As for counting characters in a string, just use the str.count() method: >>> s = "Green tree" >>> s.count("e") 4 If you are just interested in understanding why your

How to count characters in a string? (python)

拜拜、爱过 提交于 2020-01-05 12:08:19
问题 # -*- coding:UTF-8 -*- str= "Green tree" scr= "e" cstr= len(str) n=0 a=0 while n < cstr: if str[n] == scr: print(len(scr)) n=n+1 I have to count "e" in -str- string, but when I run this script I get 1 1 1 1 instead of 4. What's the problem? 回答1: First of all, don't use str as a variable name, it will mask the built-in name. As for counting characters in a string, just use the str.count() method: >>> s = "Green tree" >>> s.count("e") 4 If you are just interested in understanding why your

Python, specific count of chars in string

ε祈祈猫儿з 提交于 2020-01-05 09:03:18
问题 I am trying to count the number of occurrences in a string in python. I would like to take a binary input, say '001101'. Then count the number of 1s, 0s, 11s, 00s etc. I have tried to implement this by using count, but this will output that there are 3 1s, when i only want it to output 1 1, and 1 11s and for it to not count them individually, unless they are on their own. I have also tried to implement this with find, but i am having the same problem. Any help would be appreciated, thanks.

SUM/COUNT of CASE within CASE in MYSQL

痴心易碎 提交于 2020-01-05 06:51:29
问题 Have below Column in table product : a | b | cat -------------- 2 | 4 | 1 3 | 1 | 1 4 | 4 | 1 2 | 1 | 1 3 | 2 | 1 5 | 3 | 1 8 | 7 | 2 5 | 3 | 2 $sql = "SELECT SUM(CASE WHEN cat = 1 AND a > b THEN 1 else 0 end) as prdplus FROM product "; in above query i am getting value for sum or count of a greater then b which is 3>1 , 2>1 , 3>2 , 5>3 hence output of above query will be : 4 prdplus ------- 4 what i need is count value have only +1 in above count of 4 thats with above query now i need +1

How to count MySQL results in a has-many-through relation

て烟熏妆下的殇ゞ 提交于 2020-01-05 03:47:06
问题 There is pretty good article how to filter results in a has-many relation: How to filter SQL results in a has-many-through relation I'm just seeking a solution for COUNT result, not show them all. student { id name } club { id name } student_club { student_id club_id } How many students are in both CLUB1 && CLUB2? EDIT: It would be great to use "Martin 2" method from a link below: SELECT s.stud_id, s.name FROM student s JOIN student_club sc USING (stud_id) WHERE sc.club_id IN (30, 50) GROUP

Count the occurrences across multiple columns

江枫思渺然 提交于 2020-01-05 02:34:57
问题 Im trying to count occurrences across multiple columns in a table. All values are integers and all the numbers are unique in each row. (i.e you won't get two values occurring in the same row) The table structure is: ID Number1 Number2 Number3 Number4 Number5 Number6 --------------------------------------------------------- 11 6 4 5 9 8 6 9 11 5 3 15 8 5 9 11 4 6 4 11 17 3 7 1 The expected output would be something like: Number Count -------------- 11 4 6 3 4 3 5 3 9 3 3 2 8 2 15 1 17 1 7 1 1

How to get row number via LINQ using Entity framework?

不打扰是莪最后的温柔 提交于 2020-01-04 17:49:29
问题 Hope someone can help me out here as I'm a little stuck. I'm building a service in front of a hiscore database for a game. The database have the following two tables: CREATE TABLE [dbo].[PB_HiscoreEntry] ( [Id] UNIQUEIDENTIFIER NOT NULL, [PlayerId] UNIQUEIDENTIFIER NOT NULL, [Score] INT NOT NULL, [DateCreated] DATETIME NOT NULL ); CREATE TABLE [dbo].[PB_Player] ( [Id] UNIQUEIDENTIFIER NOT NULL, [UniquePlayerId] NCHAR (32) NOT NULL, [Name] NVARCHAR (50) NOT NULL, [DateCreated] DATETIME NOT

MySQL GROUP BY and COUNT

微笑、不失礼 提交于 2020-01-04 09:43:51
问题 I have a small problem regarding a count after grouping some elements from a mysql table, I have an orders table .. in which each order has several rows grouped by a code (named as codcomanda) ... I have to do a query which counts the number of orders per customer and lists only the name and number of orders. This is what i came up (this might be dumb ... i'm not a pro programmer) SELECT a.nume, a.tel, ( SELECT COUNT(*) AS `count` FROM ( SELECT id AS `lwtemp` FROM lw_comenzi_confirmate AS yt