Home > Software engineering >  How do you write this SQL statement
How do you write this SQL statement

Time:10-13

I now have a railway route table
Trains site
Beijing 125
Baoding 125
Anyang 125
This table records trains and site, I hope to have after Beijing and baoding train number, this statement should be how to write?
Also, the route table, so design, reasonable? If it is not reasonable, how to design?

CodePudding user response:

='Beijing' Select * from T1 where site and site='baoding' Group by trains

CodePudding user response:

The Select a. trains from T1 A Inner (Select * from T1 where site='Beijing') on a. B trains=b. trains
Where a. site='baoding Group by a. trains

CodePudding user response:

 
SELECT the cc
The FROM tb1
The WHERE (lh-zd='Beijing') OR
Baoding (lh-zd=' ')
GROUP BY cc

CodePudding user response:

Since is successively passed, then you should consider to have a direction, can consider to each site has a serial number on the mainland, trains for later maintenance and management,

CodePudding user response:

The
reference 3 floor chinaboyzyq response:
SQL code

SELECT the cc
The FROM tb1
The WHERE (lh-zd='Beijing') OR
Baoding (lh-zd=' ')
GROUP BY cc

I have a this problem... , when no hair,

CodePudding user response:

 
SELECT the cc
The FROM tb1
The WHERE (lh-zd='Beijing') OR
Baoding (lh-zd=' ')
GROUP BY cc
HAVING (COUNT (*) & gt;
=2)

CodePudding user response:

Such two must be excluded, as the upstairs said, later can become with the additional attached, such as normal arrival time, so the order can be used to reflect the time scale of sorting the search with trains

CodePudding user response:

Using a custom order
(1).
Select Id, Title
The from Archive
Where Id IN (25, 23, 19, 21, 22, 26)
The order by CHARINDEX (' | '+ LTRIM (RTRIM (STR (Id))) +' | ', '| | 23 25 19 21 22 | | | | |' 26)

(2).
-- the existing hospital administrative level data, need from low (1 b) to high (third) sorting
The CREATE TABLE # TEMP (NAME NVARCHAR (32))
INSERT INTO # TEMP (NAME) VALUES (' three ')
INSERT INTO # TEMP (NAME) VALUES (' a b)
INSERT INTO # TEMP (NAME) VALUES (' dimethyl)
INSERT INTO # TEMP (NAME) VALUES (' three b)
INSERT INTO # TEMP (NAME) VALUES (' a nail ')
INSERT INTO # TEMP (NAME) VALUES (' 2 b ')

- CHARINDEX: returns a string in the specified expression the starting position of the
SELECT * FROM # TEMP
The ORDER BY CHARINDEX (SUBSTRING (NAME, 2, 1), 'b b'),
CHARINDEX (SUBSTRING (NAME, 1, 1), 'ten')

- CHARINDEX and PATINDEX function returns the starting position of a specified pattern, PATINDEX can use wildcards, and can't CHARINDEX,
SELECT * FROM # TEMP
The ORDER BY PATINDEX (' % '+ SUBSTRING (NAME, 2, 1) +' % ', 'b b'),
PATINDEX (' % '+ SUBSTRING (NAME, 1, 1) +' % ', 'ten')

DROP TABLE # TEMP

CHARINDEX is actually two essentially method and PATINDEX


The simplest implementation
2.
Order by (case name when 'a' then the when 1 '2' then the when 2 '3' then the when 3 '4' then the when 4 '5' then 5 else 'end)

CodePudding user response:

To add a field represents the order of the each stop
  • Related