SQL關聯查詢問題

2023-02-28 17:30:18 字數 1061 閱讀 8839

1樓:

select id,date,number,price --所要查詢的資料

from t1

where number in (select number --number查詢條件,按number分組

from t1

group by number)

and date in (select max(date) --查詢按number分組,每個number最大的

from t1 date值。

group by number)

兩個限定條件,直接就可以查詢你所要求的資料,我已自己測試過,完全通過。我把兩個限定條件分開寫,就是為了讓你看得更明白一些。

有什麼不明白的可以問我,謝謝。

按你的要求我給你改了下:

select id,number,date,price

from t1

where (number,date) in (select number,max(date)

from t1

group by number

不明白再給我發訊息

2樓:匿名使用者

select * from t1 where [date] in (select max([date]) from t1 group by number)

3樓:馮益斌

select * from t1 where (cast([date] as varchar(50)) + '_' + cast([id] as varchar(50))) in

(select (cast([date] as varchar(50)) + '_' + cast([id] as varchar(50))) from t1

group by [number])

4樓:

select id,max(date) date,number, price from t1

group by id,number ,price

最近一次銷售時間也就是查詢最大的日期的商品的明細

Sql關聯查詢問題,mysql 關聯查詢求助

沒測試過 應該沒什麼大問題。select sum chngrade sum enggrade sum matgrade from select chngrade,0 enggrade,0 matgrade from a,b where and 語文 unionselect 0,0 from a,bw...

sql查詢問題

你這問題好模糊,連表欄位都沒有給出,給你大概寫下,select 訪問人 from 表 where convert varchar 7 日期欄位,120 2014 04 有問題再追問吧 select convert varchar 7 date,23 as date,count from testip...

sql查詢問題

mysql select from a id b num 1 b1 200 2 b1 300 3 b1 400 4 b2 120 5 b2 920 5 rows in set 0.00 sec mysql select b,sum num from a group by b b sum num b1...