- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我在大学参加了 SQL 类(class),但我迷失了方向。我需要创建一个销售订单数据库,显示已售商品、客人 ID、地址、价格等...
现在,这个 Improve this question 是我到目前为止所拥有的:
create table buyer (Guest int not NULL AUTO_INCREMENT,
buyer_first_name varchar(30) not null,
buyer_middle_name varchar(30) not null,
buyer_last_name varchar(30) not null,
address_street varchar(50) not null,
address_apt_num varchar(100) not null,
phone_home varchar(15) not null,
phone_mobile varchar(15) not null,
email varchar(50),
PRIMARY KEY (Guest));
create table item (ProductID int not NULL AUTO_INCREMENT,
PerUnit varchar(50) not null,
Product varchar(50) not null,
Details varchar(200),
PRIMARY KEY (ProductID));
create table sales_order (OrderID int not NULL AUTO_INCREMENT,
Guest int not null,
Date varchar(20),
SpecialInstructions varchar(200),
PRIMARY KEY (OrderID),
FOREIGN KEY (Guest) REFERENCES buyer(Guest)
)ENGINE=INNODB;
create table order_line (OrderID int not null,
ProductID int not null,
Amount int,
PRIMARY KEY (OrderID,ProductID),
FOREIGN KEY (OrderID) REFERENCES sales_order(OrderID),
FOREIGN KEY (ProductID) REFERENCES item(ProductID)
)ENGINE=INNODB;
insert into buyer(buyer_first_name,
buyer_middle_name ,
buyer_last_name ,
address_street ,
address_apt_num ,
phone_home ,
phone_mobile ,
email) values ('Naruto','Ninja','Uzumaki','1234 HokageDrive','1A', '1234567890', '1233126540','naruto@hotmail.com');
INSERT INTO item(Product,Details,PerUnit)
VALUES
('Big Burger Deluxe','Single Patty with Cheese','$1.99'),
('Double Big','2 Patties on a Bun','$2.99'),
('Happy Size Fries','10oz Fries w/ Seasoning','$0.99'),
('Chocolate Shake','Thick Chocolate Shake','$1.49'),
('Strawberry Shake','Thick Strawberry Shake','$1.49'),
('Cherry Pie','Deep-fried cherry Pie with Cream Cheese Icing.','$1.29');
INSERT INTO sales_order(SpecialInstructions,Guest,Date)
VALUES
('Please double bag the order.',1,'Sept. 2, 2015');
INSERT INTO order_line(OrderID,ProductID,Amount) VALUES (1,1,2);
现在我对 SQL 很糟糕,并且希望友好地“插入”到正确的方向。我真的很喜欢做这些事情! :)
当我运行时:
select * from buyer a
join sales_order b on
a.Guest=b.Guest
join order_line c on
b.OrderID=c.OrderID
Join item d on
c.ProductID=d.ProductID
我没有得到以下内容的预期输出:enter image description here(没有行总数)
我该从哪里开始?
附注我使用 SQL Fiddle 来完成这项作业。
更新:我的说明:提供复杂连接查询的 SQL 代码,以显示随附的“收据”中包含的所有信息以及计算属性的异常(exception)(行总计、小计、销售税和总计)。
据我了解,他们想要一次性获得所有信息?我会要求老师澄清。预期输出:
Guest ID Order ID FN MI LN Address APT# Home Cell Email Product ID Per/Unit Product Details Amount
1 1 Naruto Ninja Uzumaki 1234 Hokage Dr 1A 123 123 narutouzumaki@hotmail.com 1 1.99 Big Burger Deluxe Single patty with Cheese 2
1 1 Naruto Ninja Uzumaki 1234 Hokage Dr 1A 123 123 narutouzumaki@hotmail.com 2 2.99 Double Big 2 Patties on a Bun 2
1 1 Naruto Ninja Uzumaki 1234 Hokage Dr 1A 123 123 narutouzumaki@hotmail.com 3 0.99 Happy Size Fries 10oz Fries w/ Seasoning 4
1 1 Naruto Ninja Uzumaki 1234 Hokage Dr 1A 123 123 narutouzumaki@hotmail.com 4 1.49 Chocolate Shake Thick Chocolate Shake 1
1 1 Naruto Ninja Uzumaki 1234 Hokage Dr 1A 123 123 narutouzumaki@hotmail.com 5 1.49 Strawberry Shake Thick Strawberry Shake 3
1 1 Naruto Ninja Uzumaki 1234 Hokage Dr 1A 123 123 narutouzumaki@hotmail.com 6 1.29 Cherry Pie Deep-fried cherry Pie with Cream Cheese Icing. 2
*****点击链接 enter image description here 即可获得我认为的预期输出。**更新
我的数据很好,我能够通过内部联接查询得到它!
select
b.Guest,
b.buyer_first_name,
b.buyer_middle_name,
b.buyer_last_name,
b.address_street,
b.address_apt_num,
b.phone_home,
b.phone_mobile,
b.email,
s.OrderID,
s.`Date`,
o.ProductID,
i.PerUnit,
i.Product,
i.Details,
s.SpecialInstructions,
o.Amount
from buyer b
inner join sales_order s on b.Guest = s.Guest
inner join order_line o on s.OrderID = o.OrderID
inner join item i on o.ProductID = i.ProductID;
最佳答案
编辑:花时间在 DB-Fiddle 上玩它;
数据本身很好,只是 select 语句会给你带来悲伤。
您当前的语句是 SELECT *,并在多个表上进行联接,这意味着它将从所有表中提取所有列。查看您提供的示例图像,您不需要在一个查询中呈现所有内容。
例如,订单网格不需要buyer_first_name,但select语句包含它,而Guest信息不需要item表中的PerUnit。如果我是您,我会将 SELECT * 语句分成几个较小的语句,您可以在其中明确指定要包含哪些列。
顺便说一句:“INNER JOIN”比“JOIN”更容易阅读,特别是因为它们的含义相同,并且您可能需要能够轻松地区分各种类型的 JOIN 查询。同样,buyer.buyer_middle_name 可能不应该设置为 NOT NULL。不是每个人都有中间名。 AptNumber 也是如此。
希望这能让您朝着正确的方向前进。
关于mysql - 我对这个 SQL 项目感到非常迷失。汉堡店的销售订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51411611/
我尝试编写一个有多个链接表的解决方案。现在我有另一个问题: 我想将返回的行数限制为 1000。但我想显示 ID 1-1000,下一页 1001-2000。ID可以以不规则的顺序存储在数据库中(ID 1
我已经尝试申请 Drupal 商业优惠券大约 2 天了。我已经负责验证优惠券,但目前在尝试兑换优惠券时遇到了困难。 所以在我的回调函数中,我正在调用: my_module_coupons_coupon
[问]请帮忙,比如有一个数据 tbl_user | Id | name | | 1 | Bayu | | 2 | Indra | | 3 | Rangga | tbl_data | Id | user
我在 Android 应用程序中使用的一些 Parcelable 自定义类遇到了问题,我设法以一种非常奇怪的方式解决了这个问题。 仅在少数特定情况下,我在读取 parcelable 时发生了崩溃(这让
我一直在做一个项目,我需要在数据库中存储订单列表(在本例中为食品)。 我曾尝试四处寻找存储此类列表的最佳方式,但找不到任何方法。 目前,我将数据存储在 phpMyAdmin/SQL 中,订单存储为要打
目录 1、背景简介 2、订单业务 1、订单体系 2、流程管理 2
HBase案例:客户/订单 假设HBase 用于存储客户和订单信息。有两种核心记录类型被摄取:客户记录类型和订单记录类型。 客户记录类型将包含您通常期望的所有内容: 客户编号 客户名称
C-x C-b 显示缓冲区列表。首先是自然顺序,最近使用的缓冲区在顶部,隐藏的缓冲区在底部。 在那里,我现在可以按名称、大小、模式和文件对缓冲区进行排序。但是一旦我点击了这样的选项,我就无法回到原来的
我为 Woocommerce 添加了一个新的排序选项,它将按最低价格排序。我所有的价格都存储在一个自定义属性中,连同一些其他序列化数据。我想要的是有一个回调函数来反序列化这些数据,检查最低价格并按该价
想象一下我有一张 table : ID field1 field2 --- ------- ------ 111 1 11113 112
Kotlin forEach 是按数组的实际顺序遍历数组还是有时可能按其他顺序遍历数组?我的意思是这是否总是打印 1,2,3,...9 或者它可能会打印类似 1,5,3,4,... val numbe
我在 woocommerce 3+ 上创建了 html 电子邮件模板,但我无法通过订单 ID 获取订单项。我试过这个,但对我不起作用。 get_items(); foreach
我对将我自己的内部广告与 AdMob 的广告一起展示并使用按重要性顺序设置 eCPM 值的问题感到有些困惑。 我目前只与 AdMobs 的网络一起转换一个自家广告。 从常见问题解答和 AdMob 帮助
我正在尝试构建一个电子商务数据库,但我不了解订单,产品和客户之间的关系。 有很多数据库示例,但是它们太复杂了。是否有关于可能的表和关系的更简单的解释或示例。 谢谢。 最佳答案 如果客户可以拥有多个订单
我必须对电子商务系统进行一些更改以添加一些附加信息,并希望借此机会进行一些改进并使其更加灵活。当客户下订单时,我们必须为每个订购的商品存储几项信息;例如,产品价格、运费、征收的税款、所做的任何调整。
我正在尝试新的 ASP.NET bundle 功能,但似乎无法让我的自定义排序正常工作。这是我的 JS 文件: bootstrap.js bootstrap.min.js jquery-1.7.2.i
我正在尝试以下代码,并希望获取日期之间的所有订单并打印它们 $orders = $my_query->posts; $order = wc_get_order( $order_id ); $or
我有 ORMLite 数据库对象,它有一个字段: @ForeignCollectionField(eager = true) public ForeignCollection blocks; 现在,当
除了调用 event_list_attendees 并寻呼与会者以尝试找到正确的用户匹配之外,是否有其他方法可以获取门票/订单的用户条形码 ID?这种方法会增加 eventbrite 服务器的负担,并
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 5 年前。 我制作了订单食品应用程序。当我单
我是一名优秀的程序员,十分优秀!