I'm not sure how to word this correctly, but I need to get the sequential number on duplicates in google sheets. For example, column Count is what I'm looking for:
+-------+-------+
| Name | Count |
+-------+-------+
| Joe | 1 |
| Lisa | 1 |
| Jenny | 1 |
| Lisa | 2 |
| Lisa | 3 |
| Joe | 2 |
| Jenny | 2 |
Sample sheet: https://docs.google.com/spreadsheets/d/1BB4bzzR3TTAfW5SwvNG_W3AsIYqlSEaSOad5wB4sdko/edit#gid=0
Any help is appreciated, thanks!
For an array-enabled solution, you could try in C1
={"Count"; ArrayFormula(iferror(SORT(ROW(A2:A),SORT(ROW(A2:A),A2:A,1),1)-MATCH(A2:A,SORT(A2:A),0)-ROW()+1))}
For more background, also see this thread.
Got it, it's: =COUNTIF($A$2:A2,A2)
Related
How can I do this, and is it possible?
Please try a bit of noobish idiocy, I can't describe it better
| Monday | Tuesday | Wednesday |
+---------+---------------+-----------+
| School | Art | Verb |
| Lunch | The 3 Rows | |
| Roses | are | |
| Useless | 1 cell | |
| Dump | Number | Things |
Read about the colspan and rowspan to understand how to do this yourself, it's very simpl once you know how:
https://html.com/tables/rowspan-colspan/
I'm pretty new to SQL and I need to figure out how to run multiple sums in the same statement. For example, imagine you have a table something like this...
+----+---------------+-------------+------------+-----------+
| id | name | order_num | cost | company |
+----+---------------+-------------+------------+-----------+
| 1 | John Smith | 0 | 10.00 | CompanyA |
| 2 | Sally Thomas | 1 | 38.00 | CompanyA |
| 2 | Sally Thomas | 2 | 12.00 | CompanyA |
| 1 | John Smith | 3 | 19.00 | CompanyA |
| 2 | Jimmy John | 4 | 40.00 | CompanyB |
+----+---------------+-------------+------------+-----------+
I would like to write a query that returns the name and total sum spent for each customer at CompanyA. So basically...
+---------------+------------+
| name | total |
+---------------+------------+
| John Smith | 29.00 |
| Sally Thomas | 50.00 |
| Jimmy John | 0.00 |
+---------------+------------+
To do that I know I'm going to need to use the sum function. But everything I've tried so far results in summing up the entire column rather than the individual parts for each person. This is just a simplified example of the bigger table I'm doing this on, so I don't know any of the field data beforehand. How can I do multiple sums in one query to get this result? Thanks!
Also, I'm using MySQL if it matters.
I think you want:
select name, sum(case when company = 'CompanyA' then cost else 0 end) as Total
from t
group by name;
Thanks for your help i'm stuck on this problem.
Let me explain it, i have this kind of table :
| domain | creationdate | value 1 | value 2 |
|--------|---------------------|---------|---------|
| abc | 2013-05-28 15:35:01 | value 1 | value 2 |
| abc | 2013-04-30 12:10:10 | value 1 | value 2 |
| aaa | 2011-04-02 13:10:10 | value 1 | value 2 |
| bbb | 2012-02-12 10:48:10 | value 1 | value 2 |
| bbb | 2013-04-15 07:15:23 | value 1 | value 2 |
And i want to select (with subqueries) this :
| domain | creationdate | value 1 | value 2 |
|--------|---------------------|---------|---------|
| abc | 2013-04-30 12:10:10 | value 1 | value 2 |
| aaa | 2011-04-02 13:10:10 | value 1 | value 2 |
| bbb | 2012-02-12 10:48:10 | value 1 | value 2 |
I tried to do a combinaison of subqueries with IN/NOT IN in WHERE clause and group by/having but i'm not able to obtain a proper result.
I also have another question to ask, if someone already faced this kind of problem i would be glad to hear how he managed to figure it out.
The records in the first table you see above are frequently (every ten mins) deleted/inserted. My aim is to make a copy (or maybe a view) of the result (without the duplicates entries) which will be used 24/7 by a postfix mail server. I heard that big views (with many subqueries) decreases performances which means a table would be a preferable option. The thing is if i have to make a new table every ten mins there will be a little down time and postfix will not be able to read the table.
Waiting for your advices, thanks already.
EDIT :
Based on #Ed Gibbs answer, there is a better sample :
Source table :
| domain | creationdate | value 1 | value 2 |
|------------|---------------------|---------|---------|
| google.com | 2013-05-28 15:35:01 | john | mary |
| google.com | 2013-04-30 12:10:10 | patrick | edward |
| yahoo.fr | 2011-04-02 13:10:10 | britney | garry |
| ebay.com | 2012-02-12 10:48:10 | harry | mickael |
| ebay.com | 2013-04-15 07:15:23 | bill | alice |
With your query the result is the source table.
Desired result :
| domain | value 1 | value 2 |
|------------|---------|---------|
| google.com | patrick | edward |
| yahoo.fr | britney | garry |
| ebay.com | harry | mickael |
I want to keep the oldest domain (with the min creation date) with its own value1 and 2.
New question !
I made a view of the desired result based on your anwser.
The result look like this :
| domain | value 1 | foreign_key |
|------------|---------|-------------|
| google.com | patrick | X |
| yahoo.fr | britney | Y |
| ebay.com | harry | Z |
I also have a table with this kind of entries :
| email | value 1 | foreign_key |
|--------------------|---------|-------------|
| john#google.com | patrick | X |
| john#google.com | britney | Y |
| harry#google.com | mary | X |
| mickael#google.com | jack | X |
| david#ebay.com | walter | Z |
| alice#yahoo.com | brian | Y |
Assume that (in this sample) emails %#google.com from Y foreign_key aren't good records (only %google.com from X foreign are the good ones and also because its domain is the one i choose with the creationdate selection) how could i manage to select only emails from domain/fk referenced in my new view ?
Desired result :
| email | value 1 | foreign_key |
|--------------------|---------|-------------|
| john#google.com | patrick | X |
| harry#google.com | mary | X |
| mickael#google.com | jack | X |
| david#ebay.com | walter | Z |
| alice#yahoo.com | brian | Y |
I tried with a CONCAT('%','#',domain) and a foreign_key=foreign_key join but it doesn't give me what i want.
Based on your sample data and results, a GROUP BY will give you the results you're after:
SELECT
domain,
MIN(creationdate) AS creationdate,
value1,
value2
FROM mytable
GROUP BY domain, value1, value2
Addendum: #Arka provided updated sample data where the value 1 and value 2 columns have different values (in the original they were the same). That changes the query to this:
SELECT domain, creationdate, value1, value2
FROM mytable
WHERE (domain, creationdate) IN (
SELECT domain, MIN(creationdate)
FROM mytable
GROUP BY domain)
The subquery gets a list of the earliest creationdate for each domain, and the outer query only selects rows where the domain and creationdate match the subquery values.
I've got a excel sheet that contains all the employees that have worked for my company and is still working for us. It's a sheet of around 200 rows. Each row has basic info, like surname, name, position, qualification etc etc. 16 columns of basic info. Now, the tricky part is this. After the 16 columns, there are months (May-05 up to the present (Apr-12)). Under every month column, an employee either get's a 0 (contract), 1 (permanent), 2 (contract-terminated) or 3 (student).
What would be the best way to do this? I was thinking of 4 tables (listed below), where the one table determines permanently terminated people (for the sake of knowing who was on what type of employment).
MySQL Table: hr_employees
|-----------------|-------|----|----|----|
| employee_number | name | sur| etc| etc|
|-----------------|-------|----|----|----|
| 1 | Dave | F | xx | xx |
|-----------------|-------|----|----|----|
MySQL Table: hr_month
|----|--------|
| id | month |
|----|--------|
| 1 | May-05 |
| 2 | Jun-05 |
|----|--------|
MySQL Table: hr_status
|----|------|------|--------|
| id | e_no | date | status |
|----|------|------|--------|
| 1 | 1 | 1 | 1 |
| 2 | 1 | 2 | 1 |
|----|------|------|--------|
MySQL Table: hr_terminated
|----|------|
| id | e_no |
|----|------|
| 1 | 1 |
| 2 | 1 |
|----|------|
I hope you guys understand what I want to achieve, otherwise, ask a question, and I'll answer as best I can! :)
Thanks.
Here is a design that simplifies your data entry and is more relational database like and less Excel like, insofar as it's normalized.
MySQL Table: hr_employee
|-----------------|-------|----|----|----|
| employee_number | name | sur| etc| etc|
|-----------------|-------|----|----|----|
| 1 | Dave | F | xx | xx |
|-----------------|-------|----|----|----|
| 2 | Bob | M | xx | xx |
|-----------------|-------|----|----|----|
MySQL Table: hr_employee_status
|-----------------|------------|------------|--------|
| employee_number | from_date | to_date | status |
|-----------------|------------|------------|--------|
| 1 | 2005-05-01 | 2005-08-31 | 3 |
|-----------------|------------|------------|--------|
| 1 | 2006-05-01 | 2010-02-28 | 0 |
|-----------------|------------|------------|--------|
| 2 | 2010-03-01 | 9999-12-31 | 1 |
|-----------------|------------|------------|--------|
Here you can see that Dave was hired on as a student from May '05 to August '05, then he came back in May '06 as a contract employee which he worked as until the end of February '10. Then on March 1, 2010 Bob was hired as permanent employee and he is still working (max collating date means "until further notice").
The great advantage of this design is that you only have to enter/edit data when something changes, not once a month for every employee that you have or have ever had. You can also see what your workforce looked like at any given date (not just by months!) with a very simple SQL query.
I have a Microsoft Reporting Services report (local report, VS2005) and am trying to produce a rather tricky report...
I have two tables returned from a SQL query. The first is a master table that has a list of set ID's corresponding to sets of records in the second, and has a record set like so:
+----------------------+
| SetID |
+----------------------+
| 1 |
| 2 |
| 3 |
| ... |
| |
The second table is a list of bjorks, let's call them. It looks like this:
+----------+-------+-----------+-----------
| BjorkID | SetID | BjorkName | ...
+----------+-------+-----------+-----------
| 1 | 1 | Bob |
| 2 | 1 | Jones |
| 3 | 1 | Smith |
| 4 | 2 | Jack |
| 5 | 2 | Daniels |
| 6 | 3 | Moo |
| 7 | 3 | Bean |
| 8 | 3 | Bond |
| 9 | 3 | Jim |
| ... | ... | ... |
| | | |
Now, I need to generate a report that prints off one page for each Set, and each Set's page contains a list of its Bjorks.
Can anyone point me in the right direction to mangle RDLC into doing this? :)
Cheers!
You can accomplish your task with just the second table/data set and parent and detail groups on a table or list.
Parent groups on SetID. Detail groups on BjorkID. Set your page breaks accordingly.
HTH