22,207
社区成员
发帖
与我相关
我的任务
分享
CREATE TABLE `order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_number` varchar(255) DEFAULT NULL COMMENT '订单编号',
`create_time` timestamp NULL DEFAULT NULL COMMENT '下单时间',
`status` char(1) DEFAULT NULL COMMENT '订单状态:1待付款2待发货3发货中4待评价5已完成6已取消7已删除',
`user_id` int(11) DEFAULT NULL,
`good_num` int(11) DEFAULT NULL COMMENT '商品总数量',
`pay_method` char(1) DEFAULT NULL COMMENT '支付方式1支付宝2微信3货到付款4余额',
`pay_number` varchar(255) DEFAULT NULL COMMENT '交易号',
`pay_time` timestamp NULL DEFAULT NULL COMMENT '支付时间',
`confirm_time` timestamp NULL DEFAULT NULL COMMENT '确认收货时间',
`cancel_time` timestamp NULL DEFAULT NULL COMMENT '取消订单时间',
`is_return` char(1) DEFAULT '0' COMMENT '1退款0不退款(默认)',
`avtive_content` varchar(255) DEFAULT NULL COMMENT '满就送的整条信息',
`descr` varchar(255) DEFAULT NULL COMMENT '备注',
`pay_money` float(20,2) DEFAULT NULL COMMENT '实际支付金额',
`jf` int(11) DEFAULT '0' COMMENT '使用积分0:未使用(默认)',
`money_used` float(20,2) DEFAULT NULL COMMENT '使用的金额',
`wuliu_fee` float(20,2) DEFAULT NULL COMMENT '运费',
`reciver_name` varchar(255) DEFAULT NULL COMMENT '收货人姓名',
`reciver_phone` varchar(255) DEFAULT NULL COMMENT '收货人电话',
`reciver_addr` varchar(255) DEFAULT NULL COMMENT '收货地址',
`send_time` varchar(255) DEFAULT NULL COMMENT '配送时间',
`sender_id` int(11) DEFAULT NULL COMMENT '配送人员',
`sum` float(20,2) DEFAULT NULL COMMENT '订单金额总计(总价+运费-积分-账户余额)',
`city_id` int(11) DEFAULT NULL COMMENT '城市ID',
`delivery_time` timestamp NULL DEFAULT NULL COMMENT '配送员配送时间',
`total` float(20,2) DEFAULT NULL COMMENT '订单总价(不包含运费)',
`weixin_code` varchar(255) DEFAULT NULL COMMENT '微信返回的CODE',
`hb` float(20,2) NOT NULL DEFAULT '0.00' COMMENT '红包金额',
`hb_id` int(11) DEFAULT NULL COMMENT '红包 id',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1485 DEFAULT CHARSET=utf8;
CREATE TABLE `order_good` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) DEFAULT NULL COMMENT '订单id',
`goods_id` int(11) DEFAULT NULL COMMENT 'order_goods表的id',
`good_number` int(11) DEFAULT NULL COMMENT '该商品的数量',
`create_time` timestamp NULL DEFAULT NULL COMMENT '订单提交时间',
`good_id` int(11) DEFAULT NULL,
`goods_price` float(11,0) DEFAULT NULL COMMENT 'order_goods表单价',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3646 DEFAULT CHARSET=utf8;
CREATE TABLE `order_goods` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`good_name` varchar(255) DEFAULT NULL COMMENT '商品名称',
`descr` varchar(255) DEFAULT NULL COMMENT '简介',
`buy_price` float(20,2) DEFAULT '0.00' COMMENT '进价',
`now_price` float(20,2) DEFAULT NULL COMMENT '现价',
`old_price` float(20,2) DEFAULT NULL COMMENT '原价',
`price_change` char(1) DEFAULT '0' COMMENT '1升2将0无(默认)',
`image1` varchar(255) DEFAULT NULL,
`image2` varchar(255) DEFAULT NULL,
`image3` varchar(255) DEFAULT NULL,
`image4` varchar(255) DEFAULT NULL,
`image5` varchar(255) DEFAULT NULL,
`icon` varchar(255) DEFAULT NULL COMMENT '商品图标',
`good_type` char(1) NOT NULL COMMENT '1普通商品2整箱3兑换商品',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
`menu_id` int(11) DEFAULT NULL COMMENT '菜谱id',
`city_id` int(11) DEFAULT NULL COMMENT '城市id',
`category_id` int(11) DEFAULT NULL COMMENT '分类id',
`tag` char(1) DEFAULT '0' COMMENT '标签(0无默认,1新品2热卖3推荐4特价int',
`sale_num` int(11) DEFAULT NULL COMMENT '销量',
`dis_count` int(11) DEFAULT NULL COMMENT '评价',
`template` text COMMENT '图文详情',
`good_code` varchar(255) DEFAULT NULL COMMENT '商品编码',
`is_sale` char(1) DEFAULT NULL COMMENT '0上架1下架',
`jf_price` int(11) DEFAULT NULL COMMENT '兑换所需积分int(good_type不为3时为null)',
`good_id` int(11) DEFAULT NULL COMMENT '原始goodID',
`good_number` int(11) DEFAULT NULL COMMENT '该商品的数量',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3689 DEFAULT CHARSET=utf8;
CREATE TABLE `good` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`good_name` varchar(255) DEFAULT NULL COMMENT '商品名称',
`descr` varchar(255) DEFAULT NULL COMMENT '简介',
`buy_price` float(20,2) DEFAULT '0.00' COMMENT '进价',
`now_price` float(20,2) DEFAULT NULL COMMENT '现价',
`old_price` float(20,2) DEFAULT NULL COMMENT '原价',
`price_change` char(1) DEFAULT '0' COMMENT '1升2将0无(默认)',
`image1` varchar(255) DEFAULT NULL,
`image2` varchar(255) DEFAULT NULL,
`image3` varchar(255) DEFAULT NULL,
`image4` varchar(255) DEFAULT NULL,
`image5` varchar(255) DEFAULT NULL,
`icon` varchar(255) DEFAULT NULL COMMENT '商品图标',
`good_type` char(1) NOT NULL COMMENT '1普通商品2整箱3兑换商品',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`menu_id` int(11) DEFAULT NULL COMMENT '菜谱id',
`city_id` int(11) DEFAULT NULL COMMENT '城市id',
`category_id` int(11) DEFAULT NULL COMMENT '分类id',
`tag` char(1) DEFAULT '0' COMMENT '标签(0无默认,1新品2热卖3推荐4特价int',
`sale_num` int(11) DEFAULT NULL COMMENT '销量',
`dis_count` int(11) DEFAULT NULL COMMENT '评价',
`template` text COMMENT '图文详情',
`good_code` varchar(255) DEFAULT NULL COMMENT '商品编码',
`is_sale` char(1) DEFAULT '0' COMMENT '0上架1下架',
`jf_price` int(11) DEFAULT NULL COMMENT '兑换所需积分int(good_type不为3时为null)',
`standard` varchar(255) DEFAULT NULL COMMENT '商品规格',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=617 DEFAULT CHARSET=utf8;
order,order_good,order_goods三个表是订单表
order_goods--通过什么与order,order_good关联?除了有good_id与good关联,还有那个栏位select c.good_name,left(send_time,10) as send_time
,sum(b.good_number) as good_number
,count(distinct b.order_id) as OrderCount -- 订单数
,sum(b.good_numbe*b.goods_price) as TotalAmount -- 订单总金额
from `order` as a
inner join order_good as b on b.order_id=a.order_id
inner join good as c on c.id=b.good_id
group by c.good_name,left(send_time,10)
select c.good_name,cast(send_time as date) as send_time
,sum(b.good_number) as good_number
,count(distinct b.order_id) as OrderCount -- 订单数
,sum(b.good_numbe*b.goods_price) as TotalAmount -- 订单总金额
from `order` as a
inner join order_good as b on b.order_id=a.order_id
inner join good as c on c.id=b.good_id
group by c.good_name,cast(send_time as date)
select c.good_name
,sum(b.good_number) as good_number
,count(distinct b.order_id) as OrderCount -- 订单数
,sum(b.good_numbe*b.goods_price) as TotalAmount -- 订单总金额
from `order` as a
inner join order_good as b on b.order_id=a.order_id
inner join good as c on c.id=b.good_id
group by c.good_name
正宗原生态赣南脐橙不染色不打蜡 2 31.60 [查看详情]
沈师傅夹心蛋香菇肉丸36g 2 4.60 [查看详情]
四川甜枇杷6个/盒 1 15.60 [查看详情]
莱阳丰水梨2个装 3 12.60 [查看详情]
库尔勒香梨2斤/份 1 10.80 [查看详情]
精品烟台红富士85#3斤装 2 21.60 [查看详情]
沾化冬枣大个1斤装 1 5.60 [查看详情]
海南青金桔1斤装无核甘甜 1 13.80 [查看详情]
白心大个火龙果1斤多/个 2 13.60 [查看详情]
精选海南香蕉3斤装 3 30.00 [查看详情]
精品徐香猕猴桃中号2斤装 2 25.60 [查看详情]
台湾释迦果1斤左右(后熟水果放软才好吃) 1 19.80 [查看详情]
枣夹核桃250g/份 2 39.60 [查看详情]
马来西亚进口凤梨2斤以上 1 12.80 [查看详情]
俄罗斯进口糖果紫皮155g 1 9.90 [查看详情]
蒙牛大果粒风味发酵乳黄桃味260g 2 13.60 [查看详情]
这种类型的一个 表
还要查询下 总的订单数 ,订单总金额 这两个分开来。