选择语句问题 [英] select statement problem

查看:78
本文介绍了选择语句问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表,第一个表(id,name)和第二个表(id,date,cash).
我在表中插入了一些具有相同ID和不同日期,现金的记录.
现在我想从每个具有最少现金的ID中选择记录.(不是所有记录)
如何选择ID,名称,现金(现金必须是指定ID的最小值)

我该怎么办?
与c#2010和sql2008一起使用

i have 2 tables,first one(id,name) and second one(id,date,cash).
i insert some records in table with same id and different date,cash.
now i want to select records from every id which has minimum cash.(not all of records)
how to select id,name,cash (cash must be minimum of specified id)

what would i do?
work with c# 2010 and sql2008

推荐答案

您可以通过使用此查询来获得您的结果,


hi you can get ur result by using this query,


select * from table1 inner join table2 on table1.id =table2.id  where  cash in(select min(cash) from table2)



试试这个.
Hi,
try this one.
SELECT t1.id,MIN(t2.cash) as [minCash]
FROM tbl1 t1 INNER JOIN tbl2 t2 ON t1.id = t2.id
GROUP BY ID


< pre>从表_1中选择t1.ID,t1.Name,t2.tash现金在表t1上内部连接表_2 t2.ID = t2.ID其中Cashin(从表_2中选择min(cash));</pre>
<pre>select t1.ID,t1.Name,t2.Cash from Table_1 t1 inner join Table_2 t2 on t1.ID = t2.ID where cash in(select min(cash) from table_2);</pre>


这篇关于选择语句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆