我有一张桌子,没有钥匙. 人员(ID,姓名,家庭,日期,现金) 我在表中插入了一些具有相同ID,名称,家庭和不同日期,现金的记录. 现在我想从每个具有最少现金的ID中选择记录.(不是所有记录) 从人员中选择ID,名称,家庭,现金(现金必须是指定ID的最小值) 如果我有2张桌子,第一个(id,name)和第二个(id,date,cash).现在如何像上一个问题一样选择id,name,cash? 我该怎么办? 我希望使用c#2010
i have a table,it have no key. Personel(id,name,family,date,cash) i insert some records in table with same id,name,family and different date,cash. now i want to select records from every id which has minimum cash.(not all of records) select id,name,family,cash from personel (cash must be minimum of specified id) if i have 2 tables,first one(id,name) and second one(id,date,cash). now how to select id,name,cash like previous question? what would i do? work with c# 2010
推荐答案,我希望您的第二个表具有foreign key链接数据与第一个表. 然后在表上使用JOIN: I hope that your second table has a foreign key linking the data with the first table. Then use a JOIN on the tables: SELECT table1.id, table1.Name, table1.Family, MIN(table2.Cash) as Amount FROM table1 INNER JOIN table2 ON table1.id=Table2.table1id Group BY table1.id, table1.Name, table1.Family
Thi可能会帮助您.. 1: Thi may help you.. 1: select distinct id, MIN(cash)as Mincash,name,family,dates from Personel group by id,name,family,dates
2:第二个查询是相同的,如果您知道ID,则使用Join.
2: Second query is same use Join if you know.. on the basis of ID.
使用此查询 use this query select A.id,A.name,min(B.Cash) as Cash from table1 A inner join table2 b on A.id=B.id group by A.id,A.name
更多推荐
在sql中选择statmente
发布评论