如何在 MYSQL 中的 COUNT 中使用 SELECT
How to use SELECT inside COUNT in MYSQL
我有这样的看法:
myVIEW: (id,percent)
我想再做一个视图,会是这样的:
LASTVIEW:(lastID、lastPR、计数器)
并且在“计数器”中,在每一行中我都希望货币 id 的百分比大于该行的百分比。所以我尝试了:
CREATE VIEW LASTVIEW(lastID, lastPR, counter) AS
SELECT id AS lastID, percent AS lastPR
COUNT (SELECT id FROM myVIEW WHERE percent < lastPR) AS counter,
FROM myVIEW;
你快到了。试试这个:
SELECT id AS lastID, percent AS lastPR, (SELECT Count(id)
FROM myVIEW bigger
WHERE bigger.percent > myv.percent) AS counter
FROM myVIEW myv
使用以下 select 查询创建视图
SELECT lastID,lastPR,counter
FROM (SELECT A.id AS lastID,A.percent AS lastPR,count(B.id) AS counter
FROM myVIEW A,myVIEW B WHERE B.percent<A.percent
GROUP BY A.id,A.percent)
我有这样的看法:
myVIEW: (id,percent)
我想再做一个视图,会是这样的:
LASTVIEW:(lastID、lastPR、计数器)
并且在“计数器”中,在每一行中我都希望货币 id 的百分比大于该行的百分比。所以我尝试了:
CREATE VIEW LASTVIEW(lastID, lastPR, counter) AS
SELECT id AS lastID, percent AS lastPR
COUNT (SELECT id FROM myVIEW WHERE percent < lastPR) AS counter,
FROM myVIEW;
你快到了。试试这个:
SELECT id AS lastID, percent AS lastPR, (SELECT Count(id)
FROM myVIEW bigger
WHERE bigger.percent > myv.percent) AS counter
FROM myVIEW myv
使用以下 select 查询创建视图
SELECT lastID,lastPR,counter
FROM (SELECT A.id AS lastID,A.percent AS lastPR,count(B.id) AS counter
FROM myVIEW A,myVIEW B WHERE B.percent<A.percent
GROUP BY A.id,A.percent)