基本的Python类(Basic Python Class)
我只是试图建立一个基本的类,以便我可以学习更多关于python。 到目前为止,我有以下几点:
class Bodymassindex: count = 0 def __init__(self,name,weight,height): self.name = name self.weight = 14 * weight self.height = 12 * height notes = "no notes have been assigned yet" bmitotal = 0 Bodymassindex.count += 1 def displayCount(self): print "Total number of objects is %d" % Bodymassindex.count def notesBmi(self,text): self.notes = text def calcBmi(self): return ( self.weight * 703 ) / ( self.height ** 2 )
在添加音符变量和查看这样做的正确方法方面?
谢谢,
Im just try to build a basic class so that I can learn some more about python. So far I have the following :
class Bodymassindex: count = 0 def __init__(self,name,weight,height): self.name = name self.weight = 14 * weight self.height = 12 * height notes = "no notes have been assigned yet" bmitotal = 0 Bodymassindex.count += 1 def displayCount(self): print "Total number of objects is %d" % Bodymassindex.count def notesBmi(self,text): self.notes = text def calcBmi(self): return ( self.weight * 703 ) / ( self.height ** 2 )
In terms of adding a note variable and viewing what is the correct way of doing so ?
Thanks,
原文:https://stackoverflow.com/questions/10333878
最满意答案
您从基本聚合查询开始获取会话和颜色的计数:
select sessionNumber, colorName, count(*) as cnt from GameEvent ge group by sessionNumber, colorName;
那么你真的希望MySQL支持ANSI窗口功能 - 唯一不支持
row_number()
主要数据库。 但是,唉,这个功能不可用。 所以,你有三个选择:
- 技巧与字符串聚合。
- 变量。
- 复杂的SQL。
以下显示第一种方法:
select sessionNumber, substring_index(group_concat(colorName order by cnt desc), ',', 1) as MostCommonColor from (select sessionNumber, colorName, count(*) as cnt from GameEvent ge group by sessionNumber, colorName ) sc group by sessionNumber;
请注意,此查询存在限制。
group_concat()
的中间结果具有最大长度(由可更改的参数控制)。 另外,如果颜色名称包含逗号,那么您会希望使用不同的字符。You start with the basic aggregation query to get the counts for sessions and colors:
select sessionNumber, colorName, count(*) as cnt from GameEvent ge group by sessionNumber, colorName;
Then you really wish that MySQL supported ANSI window functionality -- the only major database that doesn't support
row_number()
. But, alas, this functionality is not available. So, you have three choices:
- Tricks with string aggregation.
- Variables.
- Complex SQL.
The following shows the first method:
select sessionNumber, substring_index(group_concat(colorName order by cnt desc), ',', 1) as MostCommonColor from (select sessionNumber, colorName, count(*) as cnt from GameEvent ge group by sessionNumber, colorName ) sc group by sessionNumber;
Note that there are limitations on this query. The intermediate results from
group_concat()
have a maximum length (controlled by a parameter that can be changed). Also, if the color names contain commas, then you would want to use a different character.
相关问答
更多-
你应该使用降序来获得最受欢迎的country : Roast.group(:country).select(:country).order("count(*) desc").first.country 你的初始错误与此无关,只是你正在使用pluck ,它返回Array对象,然后你在它上面调用first方法并获取String对象,这个对象已经是最受欢迎的烘焙名称国家,但是你试图在其上调用country ,这导致例外。 You should apply descending ordering to get t ...
-
好吧,首先我假设您的列和表名称区分大小写,这意味着您必须使用双引号。 要使用“拍摄”副本的数量打印大多数“拍摄”的书名,可以使用简单的aggragete count() ,然后将输出降序排序,最后将输出限制为1行,如: SELECT b."ID", b."Name", count(*) as takenCount FROM "TableA" a JOIN "TableB" b ON a."ID" = b."ID" WHERE a."Condition" = 'Taken' G ...
-
只是为了确认...你只关心最常见的两个miRNA条目。 因此,实质上,将miRNA#1与miRNA#2的所有gID,miRNA#3的gID等进行比较。 如果m#7与m#58共有7个基因组ID,而m#23与m#49等共有6个......下游,但m#7也可能与m#38有5个共同点。 如果是这样,您的此示例列表将显示类似的内容 miNRA7 (17's name) miNRA 58 (58's name) 7 miNRA23 (23's name) miNRA 49 (49's name) ...
-
SQL:每个ID最常见的值(SQL: Most common value per id)[2023-06-07]
您从基本聚合查询开始获取会话和颜色的计数: select sessionNumber, colorName, count(*) as cnt from GameEvent ge group by sessionNumber, colorName; 那么你真的希望MySQL支持ANSI窗口功能 - 唯一不支持row_number()主要数据库。 但是,唉,这个功能不可用。 所以,你有三个选择: 技巧与字符串聚合。 变量。 复杂的SQL。 以下显示第一种方法: select sessionNumber, ... -
在sql中找到最常见的值并按从最高到最低的顺序排序(asc)(finding the most common value in sql and ordering by highest to lowest (asc))[2021-09-23]
这看起来像你没有足够的聚合。 GROUP by中的每个字段代表一个总计与其他字段聚合的字段。 所以这只会通过id,病人和诊断向你展示诊断。 不是很有帮助。 要获得最常见的诊断期,请从分组中删除id和patient_id: select count(diagnosis) from dbo.diabetes_rx_tracker group by diagnosis order by count(diagnosis) desc 要获取所有ID中最常见的代码,请从分组中删除patient_i ... -
从DB中获取最常见的价值(Get most common value from DB)[2023-06-03]
请试试这个: SELECT city, COUNT(city) AS countcity FROM user_logins GROUP BY city ORDER BY countcity DESC LIMIT 1 Please try this: SELECT city, COUNT(city) AS countcity FROM user_logins GROUP BY city ORDER BY countcity DESC LIMIT 1 -
尝试使用可更新的CTE: DECLARE @tbl TABLE (Mnth VARCHAR(100),Premise INT, House_No INT,Street VARCHAR(100),Zip VARCHAR(100)); INSERT INTO @tbl VALUES ('Jan',43219,123,'E Haywood Dr','31214') ,('Feb',43219,123,'Haywood Dr E','31214-3291') ,('Mar',43219,123,'E Haywoo ...
-
如何只选择在常见SQL查询中具有记录值的ID?(How to select only IDs that has a record value in common SQL query?)[2024-02-05]
您需要在这两个表上应用内连接以及SET_ID上的条件。 根据您提供的描述,我尝试创建名为tbl_sets和tbl_accounts的2个表,并提出以下SQL查询: SELECT S.Set_ID,A.Acc_No from tbl_sets S INNER JOIN tbl_accounts A ON S.Acc_ID = A.Acc_ID AND S.Set_ID in (SELECT Set_ID FROM tbl_sets ts INNER JOIN tbl_accounts ... -
MySQL计数最常见的值(MySQL counting most common value)[2023-09-22]
我想你错过了这个: $row = mysql_fetch_assoc($result) $result实际上不是答案,它是包含具有答案的行的结果资源。 I think you're missing this: $row = mysql_fetch_assoc($result) The $result isn't actually the answer, it's a result resource containing the row that has the answer. -
SQL Server:最常见的值(SQL Server : most common value)[2023-03-19]
简单SUM将执行: select TOP 12 AccessoireID, count(AccessoireID) as Amount, SUM(QTE) as total_qte -- Added this from Accessoires_OrderDetails GROUP BY AccessoireID ORDER BY Amount DESC Simple SUM will do: select TOP 12 AccessoireID, ...