I have to figure out a custom SQL query within tableau to extract a singular field from a custom fields table. The table is comprised of custom fields for each candidate in a offer process. So every 10 or so rows shows the custom fields (office location, vacation days, salary, etc..) for every candidate.
I want to just extract the custom field labeled "Vacation Days". Here's my table layout:
As shown in picture, the offers table connects to the offer_custom_fields table based on "offer_id"
How do I now extract display_value when the custom_field column = "Vacation Days"?
Here's kind of my logic, but I don't know SQL at all:
SELECT
offer_id, display_value
FROM
offer_custom_fields
WHERE
custom_field = (WHERE custom_field = ‘Vacation Days’)
Any help would be greatly appreciated!
The where clause should be like:
SELECT
offer_id, display_value
FROM
offer_custom_fields
WHERE
custom_field = 'Vacation Days';
Also possible if you want to be more flexible: (The % stands for zero or more characters)
SELECT
offer_id, display_value
FROM
offer_custom_fields
WHERE
custom_field like '%Vacation Days%';
If i understood your problem this should work:
SELECT offer_id, display_value FROM offer_custom_fields WHERE custom_field = 'Vacation Days';
Related
Table 1: countries
Columns: code, country_name, full_name, continent_code.
countries table
Table 2: user_entries
Columns: active, recovered, death, createdAt
user_entries table
join tables to get countrywise data
query
select
country_name,
sum(active + recovered + death) as total,
sum(active) as active,
sum(recovered) as recovered,
sum(death) as death
from
user_entry
JOIN countries on user_entry.country_id = countries.code
group by
country_name;
output
join output
Goal
Write a query to get entries which were added in past 24 hours in a separate column, on the basis of user_entries.createdAt.
country_name
active
new_active
recovered
new_recovered
death
new_death
link to worldometers site
I am trying to achieve something similar to this.
So far I have tried using CASE but that didn't work. I also tried writing a subquery for this but was not able to figure out where to even get started.
Any help or guidance would be really appreciated.
Thanks.
I would like to iterate the same query while using different parameter values from a predefined list.
Say, I have a table with two columns. The first columns contains customer name. The second column contains customer spending.
###CUSTOMER; SPENDING###
customer1; 1000
customer2; 111
customer3; 100
customer1; 323
...
I know the complete list of customers: customerlist = {customer1, customer2, customer3}.
I would like to do something like:
Select sum(spending)
from mytable
where customer = #customerlist
The query should compute the sum of spending for each customer defined in the customer list. I have found some examples of sql procedures with stored parameters but not the case with one parameter of multiple values.
Thank you
P.S. This is just a hypothetical example to illustrate my question (I know it would be much more effective to use here a simple group by).
You can use nested query like this
SELECT CustomerList.CustomerName Cust, isnull((SELECT SUM(Spending) CustSpending
FROM Customer
WHERE Customer.CustomerName = CustomerList.CustomerName),0)
FROM CustomerList
This would normally be done using GROUP BY:
Select customer, sum(spending)
from mytable
group by customer;
GROUP BY is a very fundamental part of SQL. You should review your knowledge of SQL so you understand how to use it.
I am kind of new to SQL and I made a couple of tables to practice. The columns may have some unrelated categories but I don't know what else write...
Anyway, basically what i want to do is get info from two tables based on the first and last name from one table.
Here are my tables:
Order
Host
I want create a query to pull the ticket number, height, order, subtotal and total by first and last name. The only orders I want to pull are from John Smith And Sam Ting. So in the end, I want my extraction to have the following columns:
Ticket Number
First Name
Last Name
Height
Order
Subtotal
Total
Any help or direction would be awesome!
With the assumption the tables both have unique Ticket_Numbers and that will provide a one-to-one mapping between then.
SELECT
Order.Ticket_Number,
First_Name,
Last_Name,
Height,
Order,
Subtotal,
Total
FROM Order
JOIN Host on Host.Ticket_Number = Order.Ticket_Number
WHERE
(First_Name = 'John' AND Last_Name = 'Smith')
OR (First_Name = 'Sam' AND Last_Name = 'Ting')
You need to "call" the table name first, and then the column. After that you need to use the "join" for the 2 tables. And finally you need the "where". I didn't look for the details so you need to check the "names".
SELECT Order.Ticket_Number, Order.First_Name, Order.Last_Name, Order.Height, Order.Order, Cost.Subtotal, Cost.Total
FROM Order
INNER JOIN Cost
where First_Name="Jhon" and Last_Name="blablabla"
or
First_Name="SecondGuy" and Last_Name="blablabla"
I'm to a query multiple times from a single query in BIRT. For example, my DB2 query could be SELECT * FROM GROUPS and my dataset would look like
id | name
1 | group 1
2 | group 2
From that dataset I'd like to run another query for each row. So maybe something like SELECT * FROM ORDERS WHERE group_id = params['id'] where id is id of the current GROUP record.
The actual report would look something like:
Order for Group 1
01/01/2015 Order #321
01/15/2015 Order #948
Orders for Group 2
01/02/2015 Order #123
01/23/2015 Order #456
I'm fairly new to BIRT and have seen examples of using scripts on certain events (beforeOpen, etc), but I wanted to make sure that was the proper way to go for something this rudimentary.
Grouping on Groups in my example and OP's question, read carefully.
From what I understand of your requirements probably the easiest way to get what you want it to group on the table.
Put your fields in the data set and on the table then 'group by' elements of the table.
The report below is grouped by date and UPMC_Assign, then I count the number of INCIDENT_ID (ticket owner is criteria that is not displayed)
Create your 'Data Set', drop the Data Set on the Layout, a table is auto created.
Add a 'Group' (red circle lower part of second image), in my case I grouped by Date then by Group, in your case you would group by your 'Group'
I added an aggregation from the Palette to get counts. You can delete anything from the table you don't want. In my case i started out with a line for every ticket, but I deleted the entire row, and just show the groups and counts.
See my answer here for suggestions on versioning reports during development.
I am working in Oracle APEX.I want to make report of previous month patients treated by doctor from two tables i-e Patient and History.
Pat_id is Primary key in Patient table and foreign key in History Table.
I want report that should show me Pat_Name ,Pat_Age ,Treated_By and Date where as i can also select month from LOV(List of Value) and on the basis of that month it should show me the report.
Kindly Help me out
Thanks,
SELECT p.pat_name, p.pat_age, h.treated_by, h.date
FROM patient p
JOIN history h
ON p.pat_id = h.pat_id
WHERE EXTRACT(MONTH FROM h.date) = TO_NUMBER(:P1_MONTH)
(a really basic join condition really)
If you want ordering, you could include this in the sql, or define this in the report definition of a classic report, or as defaults in an interactive report.
P1_MONTH : a select list. As for its list of values, you can either define the months statically (12 entries with month number as return value and month name as display), or use a query:
SELECT to_char(add_months(to_date('01/01/2012','DD/MM/YYYY'),LEVEL-1),'Month') display_value, LEVEL return_value
FROM dual
CONNECT BY LEVEL <= 12
Set the select list to submit on change.
As an extra note: set your column names to be UPPERCASE in your schemas. Columns are always uppercase unless they are defined otherwise upon creation. Also be careful with using reserved keywords for things such as a column name: DATE may not be the best name for a column... Give it a useful name such as TREATED_ON