Microsoft Access - 输入参数值为什么?

时间:2012-10-17 04:53:34

标签: sql ms-access

我遇到了数据库的问题。

并尝试查询有多少交易有电影“Harry_Potter”?

所以我使用了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);

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

2 个答案:

答案 0 :(得分: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接受”

答案 1 :(得分:1)

试试这个

md.movie = "Harry_Potter"

我猜,你只是错过了你要比较的字符串周围的引号。