SQL Query for desired output [closed] - sql

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

Related

Display all countries that contain at least 2 words in the country name [closed]

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 2 years ago.
Improve this question
SELECT country_name
FROM Countries
WHERE country_name LIKE '%Word1%' AND country_name LIKE '%Word2%';
Display all countries that contain at least 2 words in the country name. It returns no results but in the system there's United states of America and United kingdom
If you want at least two words, then there is at least one space. So, if I understand correctly, you want:
where country_name like '% %'

Return value in SQL [closed]

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

SQL Query combination [closed]

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

Approver and Submitter Same Person in SQL [closed]

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

update row value with another row value [closed]

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
we have the below table
COUNTRY TOP_COUNTRY
-------------------
ST. HELENA OTHERS
BARBADOS OTHERS
UNITED STATES UNITED STATES
**RUSSIA OTHERS**
NETHERLANDS OTHERS
**GERMANY OTHERS**
ANGUILLA OTHERS
AUSTRALIA AUSTRALIA
CHINA CHINA
I would like to update TOP_COUNTRY row value for a few countries with the names as shown in COUNTRY column.
For eg:
Right now, we RUSSIA shown as 'OTHERS' in TOP_COUNTRY but i would like to update it to the 'RUSSIA'.
This needs to be done for a couple of values..
Can you please let me know how we can get this done..
You can do:
UPDATE tableName
SET TOP_COUNTRY = COUNTRY
WHERE <YourCLause>
In if you want a list of COUNTRY to be updated you can do:
WHERE COUNTRY IN ("COUNTRY1","COUNTRY2",...);
update [YourTableName] set top_country = 'RUSSIA'
where COUNTRY='RUSSIA'