在sql中选择statmente

编程入门 行业动态 更新时间:2024-10-27 14:26:58
本文介绍了在sql中选择statmente的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一张桌子,没有钥匙. 人员(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

本文发布于:2023-11-22 09:08:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:sql   statmente

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!