t_orders表:
CREATE TABLE `t_orders` (
`orderId` int(11) NOT NULL AUTO_INCREMENT,
`BuyersMes` varchar(20) DEFAULT NULL,
`orderDateTime` datetime NOT NULL,
`orderNumber` varchar(200) DEFAULT NULL,
`orderStatus` int(11) NOT NULL,
`totalPrice` double DEFAULT NULL,
`addressid` int(11) DEFAULT NULL,
`userid` int(11) DEFAULT NULL,
PRIMARY KEY (`orderId`),
UNIQUE KEY `orderNumber` (`orderNumber`),
KEY `FK7757B510A1160BFB` (`addressid`),
KEY `FK7757B51038A4A447` (`userid`)
)
t_goods表:
CREATE TABLE `t_goods` (
`goodsId` int(11) NOT NULL AUTO_INCREMENT,
`carriageTime` varchar(50) NOT NULL,
`collectCount` int(11) NOT NULL,
`commodityStocks` int(11) NOT NULL,
`goodsDecribe` longtext NOT NULL,
`goodsName` varchar(100) NOT NULL,
`goodsNumber` varchar(200) NOT NULL,
`goodsType` varchar(100) NOT NULL,
`newPrice` double NOT NULL,
`oldPrice` double DEFAULT NULL,
`sales` int(11) DEFAULT NULL,
`orders` tinyblob,
PRIMARY KEY (`goodsId`),
UNIQUE KEY `goodsNumber` (`goodsNumber`)
) 中间关联表:orders_goodsCREATE TABLE `order_goods` (
`order_id` int(11) NOT NULL,
`goods_id` int(11) NOT NULL,
PRIMARY KEY (`order_id`,`goods_id`),
KEY `FK74F24F25BA27BBF2` (`goods_id`),
KEY `FK74F24F258F090F99` (`order_id`),
CONSTRAINT `FK74F24F258F090F99` FOREIGN KEY (`order_id`) REFERENCES `t_orders` (`orderId`),
CONSTRAINT `FK74F24F25BA27BBF2` FOREIGN KEY (`goods_id`) REFERENCES `t_goods` (`goodsId`)
)
我的问题:我通过用户的ID查找到用户的订单(Orders)信息,
问题一:我想通过订单的ID获取到一个订单中所包含的
所有的商品(Goods)信息,这个该怎么查询?------------------------------------------------------------------------------------
问题二:我用的是hibernate 查询,使用对象查询的话,又该怎么写?mysqlhibernate
CREATE TABLE `t_orders` (
`orderId` int(11) NOT NULL AUTO_INCREMENT,
`BuyersMes` varchar(20) DEFAULT NULL,
`orderDateTime` datetime NOT NULL,
`orderNumber` varchar(200) DEFAULT NULL,
`orderStatus` int(11) NOT NULL,
`totalPrice` double DEFAULT NULL,
`addressid` int(11) DEFAULT NULL,
`userid` int(11) DEFAULT NULL,
PRIMARY KEY (`orderId`),
UNIQUE KEY `orderNumber` (`orderNumber`),
KEY `FK7757B510A1160BFB` (`addressid`),
KEY `FK7757B51038A4A447` (`userid`)
)
t_goods表:
CREATE TABLE `t_goods` (
`goodsId` int(11) NOT NULL AUTO_INCREMENT,
`carriageTime` varchar(50) NOT NULL,
`collectCount` int(11) NOT NULL,
`commodityStocks` int(11) NOT NULL,
`goodsDecribe` longtext NOT NULL,
`goodsName` varchar(100) NOT NULL,
`goodsNumber` varchar(200) NOT NULL,
`goodsType` varchar(100) NOT NULL,
`newPrice` double NOT NULL,
`oldPrice` double DEFAULT NULL,
`sales` int(11) DEFAULT NULL,
`orders` tinyblob,
PRIMARY KEY (`goodsId`),
UNIQUE KEY `goodsNumber` (`goodsNumber`)
) 中间关联表:orders_goodsCREATE TABLE `order_goods` (
`order_id` int(11) NOT NULL,
`goods_id` int(11) NOT NULL,
PRIMARY KEY (`order_id`,`goods_id`),
KEY `FK74F24F25BA27BBF2` (`goods_id`),
KEY `FK74F24F258F090F99` (`order_id`),
CONSTRAINT `FK74F24F258F090F99` FOREIGN KEY (`order_id`) REFERENCES `t_orders` (`orderId`),
CONSTRAINT `FK74F24F25BA27BBF2` FOREIGN KEY (`goods_id`) REFERENCES `t_goods` (`goodsId`)
)
我的问题:我通过用户的ID查找到用户的订单(Orders)信息,
问题一:我想通过订单的ID获取到一个订单中所包含的
所有的商品(Goods)信息,这个该怎么查询?------------------------------------------------------------------------------------
问题二:我用的是hibernate 查询,使用对象查询的话,又该怎么写?mysqlhibernate
问题一:我想通过订单的ID获取到一个订单中所包含的
所有的商品(Goods)信息,这个该怎么查询?
select g.*
from order_goods og,t_goods g
where order_id=123 and og.goods_id=g.goods_id
select g.*
from order_goods og,t_goods g
where order_id=7 and og.goods_id=g.goodsId