我在这里有3张桌子:
Tapes
TapesID Title Qty
T1 BatDog 3
T2 UnderCat 2
T3 IronMouse 1
T4 Boys Zone 1
T5 RoboCat 1
Borrow_Details
BTransID TSpecID Qty
BT1111 TS1 1
BT1111 TS2 1
BT1111 TS3 1
BT1112 TS1 1
BT1113 TS4 1
BT1113 TS5 1
BT1114 TS1 1
BT1114 TS6 1
BT1115 TS7 1
Tape_Specific_ID
TapesID TSpecID
T1 TS1
T1 TS2
T1 TS3
T2 TS4
T2 TS5
T3 TS6
T4 TS7
T5 TS8
T5 TS9
我的代码但是没有。 1:
DELIMITER $$
CREATE PROCEDURE list_title_ntimes (IN my_id VARCHAR(5))
BEGIN
SELECT Title FROM Tapes AND TSpecID from Tapes_SPecID WHERE ID = my_id;
END $$
DELIMITER ;
但这不起作用..
答案 0 :(得分:2)
“ ...显示磁带的标题和a的次数 特定的磁带已被借用。该过程的输入仅是 具体的身份。“
这是示例程序:
DELIMITER $$
CREATE PROCEDURE list_title_ntimes (IN my_id VARCHAR(5))
BEGIN
SELECT a.Title, COUNT(*) totalCountBorrowed
FROM Tapes a
LEFT JOIN Tape_Specific_ID b
ON a.TapesID = b.TapesID
WHERE a.TapesID = my_id;
END $$
DELIMITER ;
如果您想在不指定ID
的情况下获取所有内容,
DELIMITER $$
CREATE PROCEDURE list_title_ntimes ()
BEGIN
SELECT a.Title, COUNT(*) totalCountBorrowed
FROM Tapes a
LEFT JOIN Tape_Specific_ID b
ON a.TapesID = b.TapesID
GROUP BY a.Title;
END $$
DELIMITER ;