Python命令行输入?(Python Command Line input? [duplicate])
可能重复:
你如何从python中读取stdin什么是从命令行获取信息的最佳/最简单的方法。
例如,我将运行一堆shell脚本,它们返回:
200 SOLUTIONS_REVISION or 400 SOLUTIONS_REVISION
在我运行每个脚本之后。 我需要在python中捕获这些“返回”的字符串作为字符串(以检查它是否通过(200)或失败(400)。这是最好的方法(我是一个完整的新的python和我的搜索似乎主要是返回命令行争论。
谢谢(最好也是python 2.x)
Possible Duplicate:
How do you read from stdin in pythonWhats the best/easiest way to get information from a command line.
For example Im going to be running a bunch of shell scripts that return either:
200 SOLUTIONS_REVISION or 400 SOLUTIONS_REVISION
after I run each script. I need to capture these "returned" strings in python as a string (to check if it passes (200) or fails (400). What would be the best way to do this (im a complete newb to python and my search seemed to mainly return getting command line arguements.
Thanks (also python 2.x preferably)
原文:https://stackoverflow.com/questions/6045109
最满意答案
我不认为你可以使用简单的排名功能来做到这一点。 按时间排序并不能通过lat / lon为您提供所需的组ID,而按地理位置排序则没有多大意义。 什么工作是创建一个标志,说明lat / lon是否已更改并使用此运行总和作为序列/组ID。 然后,您可以按此分组以获得结果。
with cte as ( SELECT ID, ResourceID, Region, [GPS Time], Latitude, Longitude, lag(LATITUDE, 1) over(order by [gps time]) as prev_LATITUDE, lag(LONGITUDE, 1) over(order by [gps time]) as prev_LONGITUDE FROM [dbo].[GeofenceReport] ) , cte2 as ( select ID, ResourceID, Region, [GPS Time], Latitude, Longitude, SUM( -- 1 if location changed, 0 otherwise CASE WHEN Latitude <> prev_Latitude OR Longitude <> prev_Longitude THEN 1 ELSE 0 END ) OVER(ORDER BY [GPS Time]) as seq -- running sum over time from cte ) select min(id) as id, min(region) as region, min([GPS Time]) as [GPS Time], min(Latitude) as Latitude, min(Longitude) as Longitude from cte2 group by seq
你更新的SQL小提琴
I don't think you can do this using a simple ranking function. Ordering by time doesn't give you the desired group id by lat/lon and ordering by geo location doesn't make much sense. What would work is to create a flag saying if lat/lon changed and using running sum of this as the sequence/group id. Then you can group by that to get your results.
with cte as ( SELECT ID, ResourceID, Region, [GPS Time], Latitude, Longitude, lag(LATITUDE, 1) over(order by [gps time]) as prev_LATITUDE, lag(LONGITUDE, 1) over(order by [gps time]) as prev_LONGITUDE FROM [dbo].[GeofenceReport] ) , cte2 as ( select ID, ResourceID, Region, [GPS Time], Latitude, Longitude, SUM( -- 1 if location changed, 0 otherwise CASE WHEN Latitude <> prev_Latitude OR Longitude <> prev_Longitude THEN 1 ELSE 0 END ) OVER(ORDER BY [GPS Time]) as seq -- running sum over time from cte ) select min(id) as id, min(region) as region, min([GPS Time]) as [GPS Time], min(Latitude) as Latitude, min(Longitude) as Longitude from cte2 group by seq
Your updated SQL fiddle
相关问答
更多-
您可以使用简单的子查询来完成此操作 CREATE TABLE Table1 ([organizationID] int, [Code] int, [transactionID] int, [FGName] varchar(13), [itemName] varchar(19)); INSERT INTO Table1 ([organizationID], [Code], [transactionID], [FGName], [itemName]) VALUES (1000 ...
-
您混淆了主键和聚集索引。 两者没有理由相同。 您可以在FILE_UPLOADED_DATE上拥有聚簇索引,并在FILE_UPLOADED_DATE拥有单独的非群集主键。 事实上,你已经为DocGUID列做了类似的事情: CREATE TABLE [dbo].[FILE]( [FILE_ID] [int] IDENTITY(1,1) NOT NULL, [DOCUMENT] [varbinary](max) FILESTREAM NULL, [FILE_UPLOADED_DATE] ...
-
以下是我理解您的请求的方法:您首先需要CORRELATION_ID Z,因为其最高的SEQ (9)高于A的最高SEQ (6),但在每个CORRELATION_ID您希望按日期排序记录。 select seq, correlation_id, cr_timestamp from mytable order by max(seq) over (partition by correlation_id) desc, cr_timestamp desc; Here is how I understand your ...
-
Oracle分区使用2列(Oracle partition using 2 columns)[2022-08-30]
我觉得你很亲密。 基本上,您只需要降序排序即可获得最新版本: SELECT rc.* FROM (SELECT rc.*, RANK() OVER (PARTITION BY ID, RC_CLASS ORDER BY rc_date DESC) AS LATEST_VERSION FROM table rc ) rc WHERE LATEST_VERSION = 1 ORDER BY rc_vendorid; 我注意到你使用RANK() 。 如果您在同一日 ... -
如果要在视图中添加行号,是否只需要没有分区的order by ? 如果是这样,您可以使用以下之一,具体取决于数据库: select row_number() over () select row_number() over (order by NULL) select row_number() over (order by (select NULL)) 您的方法是枚举相同的行,而不是在所有行上提供行号。 If you want to add a row number to the view, don't ...
-
SQL最大多个列(SQL max multiple columns)[2022-06-14]
您的查询非常接近。 而不是做max ,做一个row_number() : select target_name,value,collection_timestamp from (select target_name,value,collection_timestamp, row_number() over (partition by target_name order by value desc) as seqnum from mgmt$metric_details ... -
多列SQL分区(SQL Partition By Multiple Columns)[2023-10-16]
我不认为你可以使用简单的排名功能来做到这一点。 按时间排序并不能通过lat / lon为您提供所需的组ID,而按地理位置排序则没有多大意义。 什么工作是创建一个标志,说明lat / lon是否已更改并使用此运行总和作为序列/组ID。 然后,您可以按此分组以获得结果。 with cte as ( SELECT ID, ResourceID, Region, [GPS Time], Latitude, Longitude, lag(LATITUDE, 1) over(order by [g ... -
我创建了自己的表并编写了自己的查询。 使用EXPLAIN PARTITIONS我发现使用此方法在日期上进行分区实际上使用了分区修剪。 I created my own tables and wrote my own queries. Using EXPLAIN PARTITIONS I found that partitioning on dates using this method does actually employ partition pruning.
-
您是否考虑在查询中使用QUALIFY子句? SELECT cust_grp_id , fc_id FROM table1 QUALIFY ROW_NUMBER() OVER (PARTITION BY cust_grp_id ORDER BY eff_to_dt desc) = 1; Have you considered using the QUALIFY clause in your query? SEL ...
-
如果最大技能数未知,则需要使用动态sql。 您需要使用row_number()对PersonId分区的每个列表进行编号,以便与pivot() 。 测试设置: create table t (skillid int, personid int, skill varchar(32)); insert into t values (1,1,'sql-server'),(3,1,'sql'),(9,2,'sql-server'); declare @cols nvarchar(max); declare @sql ...