首页 > 数据库 >数据库 - 第五次实验

数据库 - 第五次实验

时间:2024-02-29 14:12:09浏览次数:32  
标签:JOIN commodity cid 数据库 onsell 第五次 实验 sid orders

SELECT commodity.name,onsell.status,onsell.rem_amount,AVG(orders.buyerrate),COUNT(*)  
FROM onsell JOIN orders ON onsell.cid = orders.cid AND onsell.sid = orders.sid  
            JOIN commodity ON onsell.cid = commodity.cid  
WHERE onsell.cid = 2410 AND onsell.sid = 122

结果:

SELECT stores.name,SUM(onsell.price) 
FROM brand JOIN commodity ON brand.bid = commodity.bid   
           JOIN orders ON commodity.cid = orders.cid
           JOIN stores ON orders.sid = stores.sid
           JOIN onsell ON orders.cid = onsell.cid   
WHERE brand.name = '蒂芙尼' AND orders.sid = onsell.sid
GROUP BY stores.sid  
ORDER BY SUM(onsell.price) DESC LIMIT 5

结果:

SELECT commodity.name,onsell.price,COUNT(*)
FROM onsell JOIN commodity ON onsell.cid = commodity.cid
            JOIN orders ON onsell.sid = orders.sid AND onsell.cid = orders.cid
WHERE onsell.sid = 1
GROUP BY onsell.cid
ORDER BY COUNT(*) DESC LIMIT 10

结果:

SELECT commodity.name,sell_summary.total_sell,sell_summary.avg_buyer_rate
FROM commodity JOIN (
                    SELECT onsell.cid,SUM(onsell.price) AS total_sell,AVG(buyerrate) AS avg_buyer_rate
                    FROM onsell JOIN orders ON onsell.sid = orders.sid AND onsell.cid = orders.cid
				    WHERE orders.status = '已完成'
				    GROUP BY onsell.cid
				    ) AS sell_summary ON commodity.cid = sell_summary.cid
WHERE commodity.bid = 1

结果:

5.(疑问)

SELECT stores.name,stores.level,COUNT(orders.oid) AS total_sale,COUNT(onsell.cid)AS num_products,AVG(orders.buyerrate) AS avg_buyer_rate
FROM stores JOIN onsell ON stores.sid = onsell.sid 
            JOIN orders ON onsell.sid = orders.sid AND onsell.cid = orders.cid  
WHERE stores.sid = 1
GROUP BY stores.name, stores.level

结果:

SELECT commodity.name,brand.name,stores.name,onsell.onsell_date,onsell.rem_amount,onsell.price,AVG(orders.buyerrate)
FROM stores JOIN onsell ON stores.sid = onsell.sid
            JOIN commodity ON commodity.cid = onsell.cid
            JOIN brand ON commodity.bid = brand.bid
			JOIN orders ON onsell.sid = orders.sid AND onsell.cid = orders.cid
WHERE onsell.status = '正常' AND commodity.type = '女装'
GROUP BY onsell.sid,onsell.cid
ORDER BY AVG(orders.buyerrate) DESC LIMIT 10

结果:

先建一个视图,找出user 1购买的商品种类

CREATE VIEW user1_like
AS
SELECT commodity.type AS commodity_type,COUNT(orders.oid) AS sales_count
FROM orders JOIN user ON orders.uid = user.uid
            JOIN commodity ON orders.cid = commodity.cid
			JOIN onsell ON onsell.cid = commodity.cid
WHERE user.uid = 1  
GROUP BY commodity.name
SELECT commodity.name,commodity.type,count(orders.oid)
FROM orders JOIN commodity ON orders.cid = commodity.cid
            JOIN onsell ON onsell.cid = commodity.cid
			JOIN user1_like ON user1_like.commodity_type = commodity.type
GROUP BY commodity.type

结果:

标签:JOIN,commodity,cid,数据库,onsell,第五次,实验,sid,orders
From: https://www.cnblogs.com/XiaoZhenglld/p/18043583

相关文章

  • 数据库 - 第四次实验
    a)SELECTPeople.pid,People.name,City.nameFROMPeopleJOINCityONPeople.cid=City.cidWHEREPeople.pid=1结果:b)SELECTvaccine.name,count(*)FROMpeopleJOINinoculateONpeople.pid=inoculate.pidJOINvaccineONinoculate.vcid=vacc......
  • 数据库 - 第三次实验
    CREATEVIEWuser_friendASSELECTu2.uid,u2.nickname,f1.note,f1.typeFROMuseru1JOINfriendf1ONu1.uid=f1.uid1JOINuseru2ONu2.uid=f1.uid2WHEREu1.uid=1;运行SELECT*FROMuser_friend;结果:![[Pastedimage202311141727......
  • Oracle 12C数据库从文件系统迁移到ASM
     查看参数文件位置SQL>showparameterspfileNAMETYPEVALUE-----------------------------------------------------------------------------spfilestring/u01/app/oracle/product/12.......
  • 国产数据库兼容性认证再下两城,极狐GitLab 国产适配更进一步
    近日,极狐GitLab与两大国产数据库TDSQL和人大金仓完成兼容性认证。极狐GitLab在国产化适配、国产化生态建设上有了进一步的发展。极狐GitLab团队分别和TDSQL和人大金仓数据库团队做了严格的测试验证,完成了这两大国产数据库和极狐GitLab企业级一体化DevOps平台的兼容性认......
  • FastAPI系列:fastapi定制的数据库操作库sqlmodel
    官网sqlmodel安装#安装sqlmodel会自动安装pydantic和sqlalchemypipinstallsqlmodel使用#步骤1,创建sqlmodel引擎fromsqlmodelimportcreate_engine#driver://用户名:密码@ip/数据库engine=create_engine("mysql+mysqldb://root:123456@localhost/api")#步骤......
  • DM数据库几种主备模式说明
    前言DM数据库的主备集群主要是由搭建数据守护的方式来实现。DM数据守护(DMDataWatch)的实现原理非常简单:将主库(生产库)产生的Redo日志传输到备库,备库接收并重新应用Redo日志,从而实现备库与主库的数据同步。在此基础下,DM通过一些参数和接口的控制可以实现实时主备、读写分离集群......
  • 数据库 Tips
    数据库Tips时间和日期互转数据库当前时间字符串转时间时间转字符串格式dual表MySQLNOW()STR_TO_DATEDATE_FORMAT%Y-%m-%d%H:%i:%s可选OracleSYSTIMESTAMP、SYSDATETO_TIMESTAMP、TO_DATETO_CHARYYYY-MM-DDHH24:MI:SS必须用PostgreSQLCURRENT_......
  • Mybatis 批量更新 PostgreSQL 数据库,返回更新行数
    1.拼接成1条sql语句,可返回修改行数。PostgreSQL的批量更新原生sql:updatepersonsetname=tmp.name,age=tmp.age,addr=tmp.addr,num=tmp.num,update_time=tmp.update_timefrom(values(1,'关羽',43,'成都',1,'2021-03-2617:32:2......
  • 国产化数据库选型
    背景政府型等企业对视频会议产品有国产化方需求,其中包括国产化服务器、国产化操作系统、国产化数据库、国产化软件等,特别是国产化服务器和国产操作系统、国产化数据库,有特别明确。目前我司已选型国产化服务器为:曙光CPU,海光机器,操作系统为:KyLin-Server-V10-SP1。需求分析原私有......
  • 数据库设计规范 - 阿里
    基于阿里数据库设计规范扩展而来设计规范1.【推荐】字段允许适当冗余,以提高查询性能,但必须考虑数据一致。冗余字段应遵循:不是频繁修改的字段。不是varchar超长字段,更不能是text字段。正例:商品类目名称使用频率高,字段长度短,名称基本一成不变,可在相关联的表中冗余存储......