mysql怎么从集合中查询数据

mysql怎么从集合中查询数据,第1张

1、选中需要测试的数据库,并查看测试数据库表;由于表t_people_info中的id是主键,求id的个数即是求数据库表的总记录数,代码如下:

select count(id) from t_people_info

2、查看数据库表t_people_info中年龄中最小值,需要用到集合函数min(),代码如下:

select min(p_age) from t_people_info

3、查看数据库表t_people_info中年龄中最大值,需要用到集合函数max(),代码如下:

select max(p_age) from t_people_info

4、查看数据库表t_people_info中年龄中平均值,需要用到集合函数avg(),代码如下:

select avg(p_age) from t_people_info

5、若想统计t_people_info中的年龄的总和,用到集合函数sum(),

代码如下:

select sum(p_age) from t_people_info

6、统计数据库表中记录个数,除了使用count(主键)外,可以使用count(1)、count(*)和count(0),

代码如下:

select count(1) from t_people_info

select count(*) from t_people_info

select count(0) from t_people_info

namespace ShopModel{public class Shops{string shopname double Price int number int allnumber int singlenumber public string Shopname{get { return shopname}set { shopname = value}}public double Price1{get { return Price}set { Price = value}}public int Number{get { return number}set { number = value}} public int Allnumber{get { return allnumber}set { allnumber = value}}public int Singlenumber{get { return singlenumber}set { singlenumber = value}} }}查询所有数据private static IList<Shops>Getnumber(){string sql = "select * from Shop" List<Shops>list = new List<Shops>() using(DataTable dt = DBHelper.GetDataSet(sql)){foreach(DataRow row in dt.Rows ){Shops shop = new Shops() shop.Shopname =(string)row["SpName"] shop.Number =(int)row["SpNumber"] shop.Price1 = Convert.ToDouble( row["SpPrice"]) shop.Allnumber = (int)row["SpAllnumber"] shop.Singlenumber = (int)row["Spsinglenumber"] list.Add(shop) }return list }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/6768928.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-28
下一篇2023-03-28

发表评论

登录后才能评论

评论列表(0条)

    保存