| |

VerySource

 Forgot password?
 Register
Search
View: 711|Reply: 3

select cannot show the desired result

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-13 16:20:02
| Show all posts |Read mode
The two existing table formats are as follows
pic table:
Field name type length
aid nvarchar 50
pic nvarchar 50
pic_intro nvarchar 50

products table:
Field name type length
aid nvarchar 50
a_company nvarchar 50
a_style nvarchar 50
a_type nvarchar 50
For example: the data in the products table is
     aid a_company a_style a_type
  11111111 aaa bb cc
  22222222 aaa bb cc
  33333333 aaa cc cc
  44444444 aaa bb cc
  55555555 aaa cc cc
  
The data in the pic table is

     aid pic picintro
  11111111 aa abcd
  11111111 bb abcd
  11111111 cc abcd
  22222222 dd abcd
  22222222 ee abcd
  22222222 ff abcd
  33333333 gg abcd
  33333333 hh abcd
  33333333 ii abcd
  44444444 jj abcd
  44444444 kk abcd
  44444444 ll abcd

Now I want to combine the two tables to return search results that meet the conditions and display the values ​​of the aid distinct and pic
The debug statement is: select distinct pic.aid from products, pic where products.aid = pic.aid and a_type = 'cc' and a_style = 'bb' and products.aid <> '111111'

The results that appear are:
  aid
22222222
44444444
How do I display the following effect:

  aid pic
22222222 dd (or ee, ff is to show only one)
44444444 jj (or kk, ll)
Please master help
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-17 01:09:01
| Show all posts
select pic.aid, min (pic) from products, pic where products.aid = pic.aid and a_type = 'cc' and a_style = 'bb' and products.aid <> '111111' group by pic.aid ??
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-17 08:18:01
| Show all posts
select pic.aid, max (pic) from products, pic where products.aid = pic.aid and a_type = 'cc' and a_style = 'bb' and products.aid <> '111111' group by pic.aid
Reply

Use magic Report

0

Threads

17

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-17 10:18:01
| Show all posts
select pic.aid, min (pic) from products, pic where products.aid = pic.aid and a_type = 'cc' and a_style = 'bb' and products.aid <> '111111' group by pic.aid
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