2

我的数据库遇到问题。

并尝试查询电影《哈利波特》有多少笔交易?

所以我使用了 SQL 查询:

SELECT
COUNT(td.movie) AS number_of_occurrence,
td.transaction_number
FROM
TransactionDetails td,
MovieDetails md
WHERE
md.movie = Harry_Potter

但它要求 Harry_Potter 输入参数值为什么?相关的SQL语句是

CREATE TABLE TransactionDetails 
(
transaction_number INTEGER PRIMARY KEY,
movie VARCHAR(30) NOT NULL,
date_of_transaction DATE NOT NULL,
member_number INTEGER NOT NULL
)

CREATE TABLE MovieDetails
(
movie VARCHAR(30) PRIMARY KEY,
movie_type VARCHAR(3) NOT NULL,
movie_genre VARCHAR(10) NOT NULL
)

ALTER TABLE TransactionDetails
ADD CONSTRAINT member_number_fk FOREIGN KEY (member_number) REFERENCES    LimelightMemberDetails(member_number);

ALTER TABLE TransactionDetails
ADD CONSTRAINT transaction_number_drink_fk FOREIGN KEY (transaction_number) REFERENCES DrinkTransactionDetails(transaction_number);

ALTER TABLE TransactionDetails
ADD CONSTRAINT transaction_number_food_fk FOREIGN KEY (transaction_number) REFERENCES FoodTransactionDetails(transaction_number);

ALTER TABLE TransactionDetails
ADD CONSTRAINT movie_fk FOREIGN KEY (movie) REFERENCES MovieDetails (movie);

谢谢您的帮助!如果我的数据库设计有任何问题,请告诉我!谢谢你!

4

2 回答 2

3

将查询更改为类似

SELECT 
COUNT(td.movie) AS number_of_occurrence, 
td.transaction_number 
FROM 
TransactionDetails td, 
MovieDetails md 
WHERE 
md.movie = "Harry_Potter"

由于电影是一个字符串,因此您需要在要查找的值周围加上引号。

如果我没记错的话,MS Access 需要 " 而 SQL SERVER 需要 '

于 2012-10-17T04:59:31.923 回答
1

尝试这个

md.movie = "Harry_Potter"

我想,您只是缺少要比较的字符串周围的引号。

于 2012-10-17T04:59:45.683 回答