| |

VerySource

 Forgot password?
 Register
Search
View: 3084|Reply: 23

Ask the heroes, can such a query be realized? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

[Copy link]

1

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-19 12:00:01
| Show all posts |Read mode
Table I
A column A column
0001 1
0001 2
0001 3
0001 4
0001 5
0001 6
0001 7
0001 8
0001 9
0001 10
0001 11
0001 12
0002 10
0003 1
0003 2
0003 3
0003 4
0003 5
0003 6
0003 7
0003 8
0003 9
0003 10
0003 11
0003 12
---------------------------
I want to query the record of column A value '0002' and column B value '10' in the table above. How to query, thank you! !! !!
Reply

Use magic Report

0

Threads

35

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-6-23 14:45:02
| Show all posts
such?
select * from t where column A = '0002' and column B = '10'
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-6-23 16:15:01
| Show all posts
If requested by the landlord, upstairs can be achieved
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-6-23 16:45:01
| Show all posts
Ha ha. .
Positive solution upstairs

If the two conditions are OR relations, use OR
select * from t where column A = '0002' OR column B = '10'
Reply

Use magic Report

0

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-6-23 17:00:01
| Show all posts
select
    t.*
from
    Table 1
where
    not exists(select 1 from table one where column A=t.A and column B!=t.B)
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-23 18:00:01
| Show all posts
. . . What does the landlord mean?
Reply

Use magic Report

0

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-6-23 19:00:01
| Show all posts
declare @t table(A varchar(4),B int)
insert into @t select '0001',1
insert into @t select '0001',2
insert into @t select '0001',3
insert into @t select '0001',4
insert into @t select '0001',5
insert into @t select '0001',6
insert into @t select '0001',7
insert into @t select '0001',8
insert into @t select '0001',9
insert into @t select '0001',10
insert into @t select '0001',11
insert into @t select '0001',12
insert into @t select '0002',10
insert into @t select '0003',1
insert into @t select '0003',2
insert into @t select '0003',3
insert into @t select '0003',4
insert into @t select '0003',5
insert into @t select '0003',6
insert into @t select '0003',7
insert into @t select '0003',8
insert into @t select '0003',9
insert into @t select '0003',10
insert into @t select '0003',11
insert into @t select '0003',12

select t.* from @t t where not exists(select 1 from @t where A=t.A and B!=t.B)

/*
A B
---- -----------
0002 10
*/
Reply

Use magic Report

0

Threads

35

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-6-23 19:30:01
| Show all posts
Still like this?
select column A, min(column B) from t group by A column having count(*) = 1
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-6-23 22:00:01
| Show all posts
If there are no records in column B, only through the temporary table

select * ,id=identity(1,1) into #
from table
update b
set id=(select count(*)from # where A column=b.A column and id!>b.id)--number of records generated
from # b
Inquire
select * from # where A column = '0002' and id = '10'
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-23 23:30:02
| Show all posts
Cuddling requirements
The first floor can be achieved
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list