Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have following data on table User.
EMPID FIRSTNAME LASTNAME MANAGER
---------------------------------------
10017 Pawan Kumar 3448
3448 Anwar Sadad 1088
1088 Anand R 3525
I have 3 queries
SELECT * FROM USERS WHERE EMPID='10017';
SELECT FIRSTNAME,LASTNAME,MANAGER FROM USERS WHERE EMPID='3448';
SELECT FIRSTNAME,LASTNAME FROM USERS WHERE EMPID='1088';
Please help me combine these three query or a new query where I can select first and last name of the Manager of employ with empid 3448 who is the manager of 10017.
How can I select 1088 (Anand R) who is the Manager two level manager of 10017 (Pawan Kumar)
answer to your question will be this quesry if i have got your question right
SELECT FIRSTNAME,LASTNAME
FROM USERS
WHERE EMPID=(SELECT MANAGER
FROM USERS
WHERE EMPID=(SELECT MANAGER
FROM USERS
WHERE EMPID='10017'));
if you want to select the manager and again manager of employee with empid 10017
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
In my sql table, i have schema like,
username, FirstName, LastName, empID, manager
Jdoe John Doe 1234 Tango Charlie
Tcharlie Tango Charlie 5678 XYZ
I want to write a query that will give me, user's manager's empID.
so output should be,
Jdoe John Doe 1234 Tango Charlie 5678
I have like, 5000 records, and wanted to get a employeeID for all user's managers.
SELECT
yt1.username
, yt1.firstname
, yt1.lastname
, yt1.empid
, yt1.manager
, yt2.empid
FROM dbo.YourTable yt1
JOIN YourTable yt2 ON yt1.manager = yt2.firstname + ' ' + yt2.lastname
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a table which contains countries:
Countries
============
Australia
South Africa
Bangladesh
New zeland
Sri Lanka
England
...
Desired out put is
Country
===========
India
Sri Lanka
Followed by other countries in `Asc` or `Desc`
You can use CASE:
SqlFiddleDemo
SELECT *
FROM Countries
ORDER BY
CASE Name
WHEN 'India' THEN 0
WHEN 'Sri Lanka' THEN 1
ELSE 10
END ASC,
Name ASC -- DESC
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
We are currently building a complicated financial report where every cell in the table is link to a group of accounts. Currently we will look at the group of a accounts and we manually figure out the filter/wildcards that defines that group. We need the filters to only include the accounts in the list. I was wondering if there a program to do this for us or is there an algorithm we can implement this. Also, all account numbers will be the same length.
Example:
Group A
10004
10005
10006
21001
21023
Group B
10056
10055
Group C
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
Group A would look like 1000[4,5,6], 21001, 21023
Group B would look like 1005[5,6]
Group C would look like 1000%
One solution that comes to mind is trie.
The general algorithm would be to find the longest prefix starting from the 1-st level(not 0-th level), fix this prefix and then append the different suffixes. Hope you will guess the next steps.
For example
Group A would look like 1000[4,5,6], 21001, 21023
Trie would look like
In this case the result is: 1000[4,5,6], 210[01,23]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following table, and want to write a SQL statement to summarize every Article and Extract Maximum? :
| A | 3 |
| B | 6 |
| A | 4 |
Output: A=7, B=6.
select columnname,sum(columnname),max(expression/columnname)
from tablename
group by columnname
Something like this;
SELECT Article, SUM(Num_Column)
FROM Table_Name
GROUP BY Article
ORDER BY Article
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to identify situations in a vacation booking database where an approver and submitter are the same person. Data looks like this:
TIME VACATION BOOKING ACTION NAME
1:00:00 1 SUBMIT Mike
1:01:00 1 APPROVE Mike
1:02:00 2 SUBMIT Jane
1:03:00 2 APPROVE Mike
Is "Count" the most efficient way to do this in SQL Queries?
I would want to "catch" the Mike results in Vacation Booking 1 above.
You could use count, but I would prefer a self-join
SELECT * FROM Bookings B1
INNER JOIN Bookings B2
ON B1.[Vacation Booking]= B2.[Vacation Booking]
AND B1.Action = 'SUBMIT'
AND B2.Action = 'APPROVE'
AND B1.Name = B2.Name