首页 > 数据库 >sql练习-2

sql练习-2

时间:2023-06-24 10:33:42浏览次数:40  
标签:info goods users 练习 ecs sql order select

2023-6-19 sql语句

-- -- 以下题目涉及到的表有

-- ecs_users(用户表)、

-- ecs_order_info(订单表)、

-- ecs_goods(商品表)、

-- ecs_goods_type(商品类型表)

--

use test;

select * from ecs_users;

select * from ecs_goods;

select * from ecs_order_info;

select * from ecs_order_goods;

 

-- 1、查询电商平台的总注册用户有多少

use test;

select * from ecs_users;

select count(*) from ecs_users;

-- 2、查询电商平台的商品数量有多少?

select * from ecs_goods;

select count(goods_sn) from ecs_goods;

-- 3、查询出品牌为“资生堂”的商品的平均价格是多少?

select * from ecs_goods where goods_name like '资生堂%';

select avg(market_price) from ecs_goods where goods_name like '资生堂%';

select avg(shop_price) from ecs_goods where goods_name like '资生堂%';

-- 4、查询出品牌为“资生堂”的商品的总库存为多少?

select sum(goods_number) from ecs_goods where goods_name like '资生堂%';

-- 5、查询出电器类商品上架了多少?

select * from ecs_goods join ecs_goods_type on ecs_goods_type.cat_id = ecs_goods.cat_id where ecs_goods_type.cat_name like '%电器%';

select count(*) from ecs_goods join ecs_goods_type on ecs_goods_type.cat_id = ecs_goods.cat_id where ecs_goods_type.cat_name like '%电器%';

-- 6、查询出平台今天的总销售是多少?

select * from ecs_order_info;

select count(order_sn) from ecs_order_info;

select sum(goods_amount) from ecs_order_info where order_sn like '%20230619%';

-- 7、查询出用户名为test的用户的订单?

select * from ecs_users;

select * from ecs_order_info;

select * from ecs_order_info join ecs_users on ecs_order_info.user_id = ecs_users.user_id

where ecs_users.user_name = 'test';

-- 8、查询出所有商品中价格最贵的商品信息?

select * from ecs_goods;

select max(shop_price) from ecs_goods;

select max(market_price) from ecs_goods;

select * from ecs_goods ORDER BY shop_price desc limit 1;

-- 9、查询出平台消费能力最强的用户信息?

select * from ecs_order_info;

select sum(ecs_order_info.goods_amount), ecs_users.* from ecs_order_info join ecs_users on ecs_order_info.user_id = ecs_users.user_id group by ecs_users.user_id order by sum(ecs_order_info.goods_amount) desc limit 1;

-- 10、查询出食品类的商品有多少种?

select * from ecs_goods_type;

select * from ecs_goods;

select count(*) from ecs_goods join ecs_goods_type on ecs_goods.cat_id = ecs_goods_type.cat_id where ecs_goods_type.cat_name like '%食品%';

select * from ecs_goods where goods_name like '塞翁福%'

or goods_name like '进口橄榄油%'

or goods_name like '名野%';

-- 11、查询出有消费记录的用户信息

select ecs_users.* from ecs_order_info join ecs_users on ecs_order_info.user_id = ecs_users.user_id group by ecs_users.user_id;

-- 12、查询出有消费记录的用户的总消费额

select * from ecs_order_info;

-- select ecs_users.* from ecs_order_info join ecs_users on ecs_order_info.user_id = ecs_users.user_id group by ecs_users.user_id ;

select sum(ecs_order_info.goods_amount),ecs_users.* from ecs_order_info join ecs_users on ecs_order_info.user_id = ecs_users.user_id group by ecs_users.user_id;

-- 13、查询出只注册了账号但是没有消费过的用户信息

select * from ecs_order_info;

select ecs_users.* from ecs_users where ecs_users.user_id not in (select user_id from ecs_order_info );

-- 14、查询出消费过的用户总消费额是多少

select sum(ecs_order_info.goods_amount),ecs_users.* from ecs_order_info join ecs_users on ecs_order_info.user_id = ecs_users.user_id;

-- 15、查询出在2月份平台的销售额是多少

select * from ecs_order_info;

select sum(goods_amount),ecs_order_info.* from ecs_order_info where order_sn like '202302%';

select sum(goods_amount),ecs_order_info.* from ecs_order_info where order_sn like '202306%';

-- select unix_timestamp(now());

 

 

标签:info,goods,users,练习,ecs,sql,order,select
From: https://www.cnblogs.com/zlbstruggl/p/17500773.html

相关文章

  • 一天吃透MySQL面试八股文
    内容摘自我的学习网站:topjavaer.cn什么是MySQLMySQL是一个关系型数据库,它采用表的形式来存储数据。你可以理解成是Excel表格,既然是表的形式存储数据,就有表结构(行和列)。行代表每一行数据,列代表该行中的每个值。列上的值是有数据类型的,比如:整数、字符串、日期等等。数据库的三......
  • MySQL的wait_timeout 参数 set global 设置不生效
    MySQL服务连接数突然暴增,登录服务查看大都是sleep进程,并且1分钟会启用一个新的连接,紧急处理方案是需要手动去释放连接数。登录服务器查看当前超时时间mysql>showvariableslike'%timeout%';+-----------------------------+----------+|Variable_name|Valu......
  • MySQL 中常见的高可用架构部署方案
    MySQL中常见的高可用架构部署方案IT奋斗的青年 2023-06-0608:36 发表于山东收录于合集#mysql17个MySQL中的集群部署方案前言这里来聊聊,MySQL中常用的部署方案。MySQLReplicationMySQLReplication 是官方提供的主从同步方案,用于将一个MySQL的实例同步到另......
  • PostgreSQL 配置远程访问
    PostgreSQL安装完毕后需要设置客户端远程访问,具体步骤参考如下postgresql.conf找到配置文件目录[root@hadoop201pgsql]#locateostgresql.conf/usr/pgsql-15/share/postgresql.conf.sample/var/lib/pgsql/15/data/postgresql.conf打开文件进行编辑[root@hadoop201pgs......
  • mysql的读写分离
    读写分离的作用和实现的方式实验环境:上文的主从复制,以及新增了一台客户端进入主mysql数据库创建读写分离账号查看建立的读写分离账号挂载云计算光盘移动解压jdk一直回车后看到此询问输入yes将Java环境从1.8.0_131更改为1.6.0_14修改环境变量添加此三行数据移动jdk安装位置更新环境......
  • 通过Maxwell同步mysql数据至kafka
    实验环境本地虚拟机maraidb10.8.8kafka2.12-3.3.1maxwell由容器部署1mariadb1.1配置log_bin配置文件中加入如下内容server-id=111log_bin=mysql-binbinlog_format=ROWexpire_logs_days=1重启服务systemctlrestartmariadb查询命令SHOWVARIABLESLI......
  • debezium同步mysql数据至kafka(未完待续)
    实验环境全部部署于本地虚拟机1mysql参考官方文档和根据官方示例镜像(debezium/example-mysql,mysql版本为8.0.32)1.1创建用户官方镜像里一共有三个账号debezium:connect用户mysqluser:普通用户replicator:用于主从?设置命令createuser'debezium'@'%'identifiedby"db......
  • Scala练习
    wordCountpackagecom.doit.day03importscala.io.{BufferedSource,Source}objectWordCountDemo{defmain(args:Array[String]):Unit={//读取文件,获取到一个Source对象valsource:BufferedSource=Source.fromFile("D:\\develop\\ideaWorkSpace\\......
  • DVWA靶场之SQL注入通关详解
    原理SQL注入通过将恶意的SQL代码插入到应用程序后台的SQL语句中,以获取未授权的访问权限或者窃取应用程序中的敏感信息。通常,SQL注入攻击的目标是Web应用程序,因为Web应用程序通常需要与数据库进行交互,并且大多数Web应用程序使用的是SQL语言。存在原因Web应用程序没有对用户输入......
  • mysql基础
    一存储引擎1mysql存储引擎的种类:MYISAM InnoDB(默认)2.MYISAM和InnoDB的区别在于InnoDB支持事物处理和外键约束3.MYISAM和InnoDB的应用场景的区别:MYISAM不需要事物,空间小,已查询访问为主;InnoDB多删除,更新操作,安全性高,事物处理即并发控制查询存储文件showvariableslike'&sto......