求SQL在单表中的分类统计语句(100分)

  • 主题发起人 主题发起人 yicheng
  • 开始时间 开始时间
Y

yicheng

Unregistered / Unconfirmed
GUEST, unregistred user!
如表:table<br>id &nbsp; &nbsp; &nbsp; &nbsp; item &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in &nbsp; &nbsp; &nbsp; out &nbsp; &nbsp; &nbsp; inv<br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AAA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 50 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;50<br>2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BBB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 80 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;80 <br>3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AAA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 20 &nbsp; &nbsp; &nbsp; &nbsp;30<br>4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BBB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 40 &nbsp; &nbsp; &nbsp; &nbsp;40<br>5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BBB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 100 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 140<br>6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BBB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;160<br><br>以上为一个进销存的表,我现在要单一的筛选AAA或是BBB的话:<br>select inv form table where id=(select max(id) form table where item='AAA')<br>妈即可得到单一item的库存。<br><br>现在,我要通过一条SQL语句得到这样一个表:<br>id &nbsp; &nbsp; &nbsp; &nbsp; item &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inv<br>3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AAA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;30<br>6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BBB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;160 <br><br>如何做?
 
select id,item,inv from table<br>where id in (<br>&nbsp; select max(id) from table group by item<br>)
 
接受答案了.
 
后退
顶部