我有几张电影 DVD,想在 MySQL 中创建一个简单的数据库。PF DB 结构。我有一个 MySQL 查询,它实际上没有列出确切的编号。我有的电影。下面的查询是 -
SELECT SUM(Total) as total
FROM (
SELECT COUNT(DISTINCT(Movie1)) AS Total FROM tbl_movie
WHERE Movie1 !='' AND Movie1 IS NOT NULL AND DVDCategory='Movie'
UNION
SELECT COUNT(DISTINCT(Movie2)) FROM tbl_movie
WHERE Movie2 !='' AND Movie2 IS NOT NULL AND DVDCategory='Movie'
UNION
SELECT COUNT(DISTINCT(Movie3)) FROM tbl_movie
WHERE Movie3 !='' AND Movie3 IS NOT NULL AND DVDCategory='Movie'
UNION
SELECT COUNT(DISTINCT(Movie4)) FROM tbl_movie
WHERE Movie4 !='' AND Movie4 IS NOT NULL AND DVDCategory='Movie'
UNION
SELECT COUNT(DISTINCT(Movie5)) FROM tbl_movie
WHERE Movie5 !='' AND Movie5 IS NOT NULL AND DVDCategory='Movie'
UNION
SELECT COUNT(DISTINCT(Movie6)) FROM tbl_movie
WHERE Movie6 !='' AND Movie6 IS NOT NULL AND DVDCategory='Movie'
UNION
SELECT COUNT(DISTINCT(Movie7)) FROM tbl_movie
WHERE Movie7 !='' AND Movie7 IS NOT NULL AND DVDCategory='Movie'
) AS Total;
数据库结构 -
ID DVD Movie1 Movie2 Movie3 Movie4 Movie5 Movie6 Movie7
__________________________________________________________________
1 1 IronMan Movie11 MindHunters 300 Jumper 7
2 2 IronMan2 Movie22 Grey Blood Diamond
3 3 Movie33 Red Eye Departed 300
4 4 Movie44 Gladiator King Kong
5 5 Movie55 Hitman
它在 DB 中显示 13 个结果而不是 18 个电影。我搜索了您的问题列表,但没有找到任何合适的答案。你能告诉我哪里出错了,或者有什么更好的方法可以安排这个查询吗?