Home > database >  A simple SQL query problem of primary amateurs
A simple SQL query problem of primary amateurs

Time:09-29



Find all the capital and the country name, and in the capital have the country name,
The select capital, name the from world

Where the name in (capital) should I write the correct answer is the following


Capital name
Andorra la Vella Andorra
Djibouti Djibouti
Guatemala City, Guatemala
Kuwait City, Kuwait
Luxembourg Luxembourg
Mexico City, Mexico
Monaco Ville - Monaco
Panama City, Panama
San Marino San Marino
Singapore Singapore

CodePudding user response:

Please post table structure, the test data of the script...

CodePudding user response:

 
The select capital, name the from world
Where charindex (name, capital) & gt; 0

CodePudding user response:

Capital name
Kabul Afghanistan
Tirana Albania
Algiers Algeria
Andorra la Vella Andorra
Luanda Angola
St. John 's Antigua and Barbuda
Buenos Aires Argentina
Yerevan Armenia
Canberra Australia
Vienna Austria
Baku Azerbaijan
Nassau last
Manama Bahrain
Dhaka Bangladesh
Bridgetown Barbados
In Minsk Belarus
The City of Brussels Belgium
Belmopan Belize
Porto Novo Benin -
Thimphu Bhutan
Sucre can
Sarajevo Bosnia and Herzegovina
Gaborone Botswana
Brasilia Brazil
Bandar Seri Begawan Begawan Brunei
Sofia Bulgaria
Ouagadougou Burkina Faso
Bujumbura Burundi
Up Phnom Penh Cambodia
Yaounde Cameroon
Ottowa Canada
Praia Cape Verde
Bangui Central substitutes Republic
N 'Djamena Chad
Santiago Chile
Beijing China
Reuters Colombia
Moroni Comoros
The United States today Kinshasa, Congo Republic of
Brazzaville, Congo Republic of
San Jose Costa Rica
Yamoussoukro C? Te d 'Ivoire
Zagreb Croatia
And Havana Cuba
Nicosia Cyprus
The incapable Czech Republic
Copenhagen Denmark,
Djibouti Djibouti
Roseau Dominica
Santo Domingo Dominican Republic

This is the original table

CodePudding user response:

refer to the second floor qq_37170555 response:
 
The select capital, name the from world
Where charindex (name, capital) & gt; 0
you try this

CodePudding user response:

reference 4 floor weixin_41673886 response:
Quote: refer to the second floor qq_37170555 response:

 
The select capital, name the from world
Where charindex (name, capital) & gt; 0
you tried not

 
--> --> The rain has stopped, & gt; Generate test data

If not object_id (N 'Tempdb for.. # TAB ') is null
Drop table # TAB
Go
The Create table # TAB ([capital] nvarchar (27), [name] nvarchar (31))
Insert # TAB
Select N 'Kabul', N 'Afghanistan' union all
Select N 'Tirana', N 'Albania' union all
Select N 'Algiers', N' Algeria 'UNION ALL
SELECT 'Kuwait City' and 'Kuwait' UNION ALL
SELECT 'Djibouti', 'Djibouti'
Go
Select * from # TAB
WHERE charindex (name, capital) & gt; 0


Why not, you are the SQL server

CodePudding user response:

reference 5 floor qq_37170555 reply:
Quote: refer to 4th floor weixin_41673886 response:

Quote: refer to the second floor qq_37170555 response:

 
The select capital, name the from world
Where charindex (name, capital) & gt; 0
you tried not

 
--> --> The rain has stopped, & gt; Generate test data

If not object_id (N 'Tempdb for.. # TAB ') is null
Drop table # TAB
Go
The Create table # TAB ([capital] nvarchar (27), [name] nvarchar (31))
Insert # TAB
Select N 'Kabul', N 'Afghanistan' union all
Select N 'Tirana', N 'Albania' union all
Select N 'Algiers', N' Algeria 'UNION ALL
SELECT 'Kuwait City' and 'Kuwait' UNION ALL
SELECT 'Djibouti', 'Djibouti'
Go
Select * from # TAB
WHERE charindex (name, capital) & gt; 0


Why not, you of whether SQL server
my online test question is this

CodePudding user response:

refer to 6th floor weixin_41673886 response:
Quote: refer to the fifth floor qq_37170555 reply:

Quote: refer to 4th floor weixin_41673886 response:

Quote: refer to the second floor qq_37170555 response:

 
The select capital, name the from world
Where charindex (name, capital) & gt; 0
you tried not

 
--> --> The rain has stopped, & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related