count

Get row count of table while inserting data in table

十年热恋 提交于 2021-02-10 17:59:10
问题 Here is Sample Data and Schemas CREATE TABLE [dbo].[Customer]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](500) NOT NULL, [IsDelete] [bit] NOT NULL, CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TABLE [dbo].[Invoice]([Id] [int] IDENTITY(1,1) NOT NULL,[CustomerId] [int] NOT NULL, [Amount] [decimal](18, 2) NOT NULL,

Count by condition applied to the same column in Pandas

帅比萌擦擦* 提交于 2021-02-10 06:14:09
问题 This is my data frame. acc_index veh_count veh_type 001 1 1 002 2 1 002 2 2 003 2 1 003 2 2 004 1 1 005 2 1 005 2 3 006 1 2 007 2 1 007 2 2 008 2 1 008 2 1 009 3 1 009 3 1 009 3 2 acc_index is unique for each accident veh_count shows how many vehicles are involved in one accident veh_type shows the type of vehicles involved in an accident (1=bicycle, 2=car, 3=bus). What I want to do is to count the number of accidents between cars and bicycles (so, where veh_type=1 and veh_type=9 for the same

Count on join of big tables with conditions is slow

孤街浪徒 提交于 2021-02-10 06:11:54
问题 This query had reasonable times when the table was small. I'm trying to identify what's the bottleneck, but I'm not sure how to analyze the EXPLAIN results. SELECT COUNT(*) FROM performance_analyses INNER JOIN total_sales ON total_sales.id = performance_analyses.total_sales_id WHERE (size > 0) AND total_sales.customer_id IN ( SELECT customers.id FROM customers WHERE customers.active = 't' AND customers.visible = 't' AND customers.organization_id = 3 ) AND total_sales.product_category_id IN (

Pandas GroupBy : How to get top n values based on a column

ぐ巨炮叔叔 提交于 2021-02-10 03:56:34
问题 forgive me if this is a basic question but i am new to pandas. I have a dataframe with with a column A and i would like to get the top n rows based on the count in Column A. For instance the raw data looks like A B C x 12 ere x 34 bfhg z 6 bgn z 8 rty y 567 hmmu,,u x 545 fghfgj x 44 zxcbv Note that this is just a small sample of the data that i am actually working with. So if we look at Column A, value x appears 4 times,y appears 2 times and z appears 1 time. How can i get the top n values

SQL SUM and COUNT returning wrong values

一笑奈何 提交于 2021-02-08 11:47:19
问题 I found a bunch of similar questions but nothing worked for me, or I am too stupid to get how to do it right. The visit count works fine if I use COUNT(DISTINCT visits.id) but then the vote count goes totally wrong - it displays a value 3 to 4 times larger than it should be. So this is the query SELECT SUM(votes.rating), COUNT(visits.id) FROM topics LEFT JOIN visits ON ( visits.content_id = topics.id ) LEFT JOIN votes ON ( votes.content_id = topics.id ) WHERE topics.id='1' GROUP BY topics.id

Using powershell to count number of files in subfolder with specific name

夙愿已清 提交于 2021-02-08 09:47:07
问题 So I've started working on a problem where I need to know how many files are in a subfolder of a certain name, that is repeated multiple times in throughout the directory. All folders I want to count have the same name. For example: Main Folder Subfolder Folder I want to count Folder A Folder B Subfolder Folder I want to count Folder C Folder D I'm able to count the number of files in all subfolders recursively, but I don't know how to only look at folders named " Folder I want to count ".

Counting the number of consecutive years in r

我怕爱的太早我们不能终老 提交于 2021-02-08 08:52:06
问题 I have a vector A containing years: eg. A <- c(1978, 1979, 1980, 1981, 1984, 1987,1988,1989,1990,1991, 1992) I would like to be able to count the sequence of years before a year is missed out. So I would be looking for my answer to be : 4, 1, 6 I know about using rle for sequences of repeated numbers but not sure what to do here. 回答1: Assuming A is sorted: A <- c(1978, 1979, 1980, 1981, 1984, 1987,1988,1989,1990,1991, 1992) B <- cumsum(c(1, diff(A)>1)) rle(B)$lengths #[1] 4 1 6 来源: https:/

SQL/PHP: Show top 3 most sold products from database

扶醉桌前 提交于 2021-02-08 08:39:25
问题 I have a database containing the following tables: - product (product_id / name / price / image_id / description) - order ( order_id / date / status / email ) - order_count ( order_id / product_id / number ) - image (image_id / image_link ) I'd like to show the 3 most sold products on my homepage, but can't wrap my head around doing this. I tried this: $sql = "SELECT" * FROM 'product' INNER JOIN 'afbeelding' WHERE 'product'.'image_id' = 'afbeelding'.'image_id' GROUP BY 'product_id' ORDER BY

MySQL query - join 3 tables together, group by one column and count for the other 2

試著忘記壹切 提交于 2021-02-08 07:33:30
问题 Here are examples of the 3 tables I'm working with. Teams +----+------+ | id | name | +----+------+ | 1 | abc | | 2 | def | | 3 | ghi | +----+------+ Members +----+-----------+----------+---------+ | id | firstname | lastname | team_id | +----+-----------+----------+---------+ | 1 | joe | smith | 1 | | 2 | jared | robinson | 1 | | 3 | sarah | cole | 3 | | 4 | jaci | meyers | 2 | +----+-----------+----------+---------+ Goals +----+-----------+ | id | member_id | +----+-----------+ | 1 | 3 | |

Query using aggregation and/or groups in relational algebra - count, max, min, etc

断了今生、忘了曾经 提交于 2021-02-08 05:13:07
问题 I have read much in textbooks and browsed a lot of pages on the internet but I can't understand how functions/operators like min, max, count, ... that aggregate over a relation/table or groups of tuples/rows in a relation/table are built with basic operations such as ∪ (union), ∩ (intersection), x (join), - (minus), π (projection), .... Can anyone show me how to express these functions/operators with relational algebra? 回答1: Computing functions in relation algebra are not fully included yet.