I am using Tableau Public to read data from a '|' separated text file. The goal is to determine how much damage each player dealt versus received. Currently the data only shows rows for each attacker. How can I change the data so that I see a row for each player?
Sample Source:
Attacker Name | Attacker Nation | Defender Name | Defender Nation | Attacking Damage | Defending Damage
Bob | Builder | Felix | Fixer | 100 | 120
Bob | Builder | Ralph | Wrecker | 150 | 75
Felix | Fixer | Ralph | Wrecker | 125 | 150
Desired Output:
Name | Nation | Opponent Name | Opponent Nation | Damage Dealt | Damage Received
Bob | Builder | Felix | Fixer | 100 | 120
Bob | Builder | Ralph | Wrecker | 150 | 75
Felix | Fixer | Bob | Builder | 120 | 100
Felix | Fixer | Ralph | Wrecker | 125 | 150
Ralph | Wrecker | Bob | Builder | 75 | 150
Ralph | Wrecker | Felix | Fixer | 150 | 125
Related
I was practicing on some subqueries and I got stuck on a problem. This is for the table below (snippet). The question is "From the following tables, write a SQL query to find those employees whose salaries exceed 50% of their department's total salary bill. Return first name, last name."
My query is this below, but it does not run. I ran the subquery by itself, and it ran fine. I think it's something to do with the GROUP BY in the subquery.
SELECT first_name, last_name
FROM employees
WHERE salary >
(
SELECT (sum(salary)) / 2
FROM employees
GROUP BY department_id
)
The correct answer from the practice is below. Is creating table e2 necessary?
SELECT e1.first_name, e1.last_name
FROM employees e1
WHERE salary >
( SELECT (SUM(salary))*.5
FROM employees e2
WHERE e1.department_id=e2.department_id);
+-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------+------------+---------------+
| EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMAIL | PHONE_NUMBER | HIRE_DATE | JOB_ID | SALARY | COMMISSION_PCT | MANAGER_ID | DEPARTMENT_ID |
+-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------+------------+---------------+
| 100 | Steven | King | SKING | 515.123.4567 | 2003-06-17 | AD_PRES | 24000.00 | 0.00 | 0 | 90 |
| 101 | Neena | Kochhar | NKOCHHAR | 515.123.4568 | 2005-09-21 | AD_VP | 17000.00 | 0.00 | 100 | 90 |
| 102 | Lex | De Haan | LDEHAAN | 515.123.4569 | 2001-01-13 | AD_VP | 17000.00 | 0.00 | 100 | 90 |
| 103 | Alexander | Hunold | AHUNOLD | 590.423.4567 | 2006-01-03 | IT_PROG | 9000.00 | 0.00 | 102 | 60 |
| 104 | Bruce | Ernst | BERNST | 590.423.4568 | 2007-05-21 | IT_PROG | 6000.00 | 0.00 | 103 | 60 |
| 105 | David | Austin | DAUSTIN | 590.423.4569 | 2005-06-25 | IT_PROG | 4800.00 | 0.00 | 103 | 60 |
| 106 | Valli | Pataballa | VPATABAL | 590.423.4560 | 2006-02-05 | IT_PROG | 4800.00 | 0.00 | 103 | 60 |
| 107 | Diana | Lorentz | DLORENTZ | 590.423.5567 | 2007-02-07 | IT_PROG | 4200.00 | 0.00 | 103 | 60 |
| 108 | Nancy | Greenberg | NGREENBE | 515.124.4569 | 2002-08-17 | FI_MGR | 12008.00 | 0.00 | 101 | 100 |
| 109 | Daniel | Faviet | DFAVIET | 515.124.4169 | 2002-08-16 | FI_ACCOUNT | 9000.00 | 0.00 | 108 | 100 |
| 110 | John | Chen | JCHEN | 515.124.4269 | 2005-09-28 | FI_ACCOUNT | 8200.00 | 0.00 | 108 | 100
SELECT first_name, last_name
FROM employees
WHERE salary >
(
SELECT (sum(salary)) / 2
FROM employees
GROUP BY department_id
)
I expected this to run, but it did not execute. The editor on the website I'm practicing from does not give error info.
I know this has been asked a bit on here and I have tried several of the answers with no progress. My goal is to be able to also see which Tracking Numbers had 0 calls during the date range.
I have tried several joins, sub-queries, and way to much time. Any help would be greatly appreciated.
SELECT org_unit_name "Group Name",
call_detail.ring_to_name "Ad Source(s)",
tracking "Tracking Number",
COUNT(call.call_id)"Calls",
SUM(bill_second)/60 "Total Duration (Sec)"
FROM CALL
JOIN call_detail ON call.call_id = call_detail.call_id
JOIN org_unit o ON call.org_unit_id = o.org_unit_id
WHERE billing_id = 3104
AND call_started BETWEEN '2020-01-01' AND '2020-01-31'
GROUP BY 1,2,3
Here is a sample of how the data is coming back:
| Group Name | Ad Source(s) | Tracking Number | Calls | Total Duration (Sec) |
|--------------------------|------------------------------|-----------------|-------|----------------------|
| Westin Riverfront Villas | Desert Willow Explorer | 8883926768 | 2 | 9 |
| Sheraton Maui | Postcard-Owner | 8885322865 | 36 | 82 |
| Westin Maui | CS On-Site Pre Arrival calls | 8885939052 | 35 | 128 |
| Sheraton Kauai | Email Renter | 8887248492 | 24 | 91 |
But I need 6th and 8th line to show up as well even/especially since they have had no calls.
Westin Princeville and Westin Nanea Resort had no calls but should be on the report
| Group Name | Ad Source(s) | Tracking Number | Calls | Total Duration (Sec) |
|--------------------------|---------------------------------|-----------------|-------|----------------------|
| Westin Maui | CS On-Site Pre Arrival calls | 8885939052 | 35 | 128 |
| Westin Riverfront Villas | Desert Willow Explorer | 8883926768 | 2 | 9 |
| Sheraton Kauai | Email Renter | 8887248492 | 24 | 91 |
| Westin Princeville | In-House pre-arrival phone call | 8776921840 | 0 | 0 |
| Sheraton Maui | Postcard-Owner | 8885322865 | 36 | 82 |
| Westin Nanea Resort | Pre-Arrival E-Mail Nanea WVP | 8887218839 | 0 | 0 |
I am new to Tableau and I have requirements as below:
I need to create a dashboard with a filter on Paywave or EMV and show count of Confirmed and Probable on a geo map.
When I select EMV from the quick filter, it should show a count of confirm & probable for that city. I should be able to drill down and see a count of confirm and probable for zip codes as well.
I am not sure how to achieve the above requirements.
As shown below I have fields like:
EMV Paywave
mrchchant_city, mrch_zipcode confirm probable confirm probable
A 1001 10 15 20 18
B 1005 34 67 78 12
C 2001 24 56 76 45
C 2001 46 19 63 25
Please let me know if any information required from my side.
This will be a lot easier on you if you restructure your data a bit. More often than not, the goal in Tableau is to provide an aggregated summary of the data, rather than showing each individual row. We'll want to group by dimensions (categorical data like "EMV"/"Paywave" or "Confirm"/"Probable"), so this data will be much easier to work with if we get those dimensions into their own columns.
Here's how I personally would go about structuring your table:
+----------------+--------------+---------+----------+-------+-----+
| mrchchant_city | mrch_zipcode | dim1 | dim2 | count | ... |
+----------------+--------------+---------+----------+-------+-----+
| A | 1001 | Paywave | confirm | 20 | ... |
| A | 1001 | Paywave | probable | 18 | ... |
| A | 1001 | EMV | confirm | 10 | ... |
| A | 1001 | EMV | probable | 15 | ... |
| B | 1005 | Paywave | confirm | 78 | ... |
| B | 1005 | Paywave | probable | 12 | ... |
| B | 1005 | EMV | confirm | 34 | ... |
| B | 1005 | EMV | probable | 67 | ... |
| C | 2001 | Paywave | confirm | 76 | ... |
| C | 2001 | Paywave | probable | 45 | ... |
| C | 2001 | EMV | confirm | 24 | ... |
| C | 2001 | EMV | probable | 56 | ... |
| C | 2001 | Paywave | confirm | 63 | ... |
| C | 2001 | Paywave | probable | 25 | ... |
| C | 2001 | EMV | confirm | 46 | ... |
| C | 2001 | EMV | probable | 19 | ... |
| ... | ... | ... | ... | ... | ... |
+----------------+--------------+---------+----------+-------+-----+
(Sorry about the dim1 and dim2, I don't really know what those dimensions represent. You can/should obviously pick a more intuitive nomenclature.)
Once you have a table with columns for your categorical data, it will be simple to filter and group by those dimensions.
I'm currently using Sphinx MVAs (Multi Value Attribute) for indexer performance reasons, each MVA only has a single value. I'm basically using the MVA's in the same way as a sql_joined_field (I can't use sql_joined_field since you cannot filter by joined values).
I want to be able to sort by the value of the MVA. According to sphinx docs, you cannot actually do this, however, you can sort by selected derived values. (eg, MAX(price) AS sort_field or GROUP_CONCAT(tag) AS sort_field)
Is there a way to select a single value from the MVA (or possibly concatenating all values in the MVA)?
ok, while it appears you can sort by a MVA,
sphinxQL>select id,bucket_id from gi_stemmed where match('bridge') order by bucket_id desc;
+---------+-----------+
| id | bucket_id |
+---------+-----------+
| 4135611 | 492 |
| 4135609 | 492 |
| 4132078 | 492 |
| 4130626 | 492 |
| 4117904 | 492 |
| 4114632 | 490 |
| 4087884 | 490 |
| 4087786 | 490 |
| 4087767 | 490 |
| 4087010 | 490 |
| 4086927 | 490 |
| 4086920 | 490 |
| 4086125 | 490 |
| 4083465 | 761 |
| 4081812 | 491 |
| 4081713 | 490 |
| 4065533 | 490 |
| 4065427 | 490 |
| 4065338 | 490 |
| 4065321 | 490 |
+---------+-----------+
Server version: 2.2.1-dev (r4133)
ie no error. It doesn't work completely. There are a few results out of order (see 2/3rds down in the example above)
But there is a GREATEST() function, which works like MAX in your question.
sphinxQL>select id,bucket_id,greatest(bucket_id) as two from gi_stemmed where match('bridge road') order by two desc;
You can sort by MVA's...
sphinxQL>select id,bucket_id from gi_stemmed order by bucket_id desc;
+---------+-----------+
| id | bucket_id |
+---------+-----------+
| 4138739 | 492 |
| 4138708 | 492 |
| 4138671 | 492 |
| 4138663 | 492 |
| 4138661 | 492 |
| 4138615 | 492 |
bucket_id is a MVA (for a similar reason to you)
sphinxQL>describe gi_stemmed like 'bucket_id';
+-----------+------+
| Field | Type |
+-----------+------+
| bucket_id | mva |
+-----------+------+
Server version: 2.2.1-dev (r4133)
I've created a report that is supposed to use a tablix to group data exactly as seen below:
Region | State | Customer | CustomerKey | Status
North | NY | Bob | 111 | VIP
| | Mary | 112 | VIP
| MA | Bob | 111 | Regular
| | Tim | 113 | Regular
East | MD | Greg | 114 | VIP
| VA | Bob | 111 | VIP
West | CA | Greg | 114 | Regular
| | Mary | 112 | VIP
| | Sean | 115 | Regular
| WA | Sean | 115 | VIP
This is relatively easy because I am using a view with all the appropriate fields and relations to make grouping in the tablix simple. I only run into a problem with my VIP Customers.
In the view, customers who have VIP status also have duplicate records of them with Regular status. For example, the data is stored as follows:
Region | State | Customer | CustomerKey | Status
North | NY | Bob | 111 | VIP
North | NY | Bob | 111 | Regular
North | NY | Mary | 112 | VIP
North | NY | Mary | 112 | Regular
North | MA | Bob | 111 | Regular
North | MA | Tim | 113 | Regular
East | MD | Greg | 114 | VIP
East | MD | Greg | 114 | Regular
East | VA | Bob | 111 | VIP
East | VA | Bob | 111 | Regular
West | CA | Greg | 114 | Regular
West | CA | Mary | 112 | VIP
West | CA | Mary | 112 | Regular
West | CA | Sean | 115 | Regular
West | WA | Sean | 115 | VIP
West | WA | Sean | 115 | Regular
My SSRS report is therefore displaying the data as follows:
Region | State | Customer | CustomerKey | Status
North | NY | Bob | 111 | VIP
| | | | Regular
| | Mary | 112 | VIP
| | | | Regular
| MA | Bob | 111 | Regular
| | Tim | 113 | Regular
East | MD | Greg | 114 | VIP
| | | | Regular
| VA | Bob | 111 | VIP
| | | | Regular
West | CA | Greg | 114 | Regular
| | Mary | 112 | VIP
| | | | Regular
| | Sean | 115 | Regular
| WA | Sean | 115 | VIP
| | | | Regular
If a user has a Status of VIP, I don't care about their record with their Status of Regular (for that particular Region/State). Is there anyway I can hide these conditionally? Thanks in advance
Personally I'd look at solving this at a database query level in the first instance.
That said, one way at the report level would be to set up Groups based on Region, State and Customer, then in the Status column you could have an expression like:
=IIf(CountRows("CustomerGroup") = 2, "VIP", "Regular")
It's a bit clunky, but should work as it seems each customer can either have one or two rows at the Region/State level - if two they must be VIP, and since you've set a a group you're getting distinct values for Customers within each Region/State combo.