6

I have this view:

myVIEW: (id,percent)

I want to make another view, which will be like this:

LASTVIEW: (lastID, lastPR, counter)

and in "counter", in every line I want to have how money id`s have a bigger percent than the percent of this line. so I tried:

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;
1
  • Use your other query as a subquery in your FROM. Read this Commented May 14, 2015 at 19:05

2 Answers 2

9

Your are almost there. Try this:

SELECT id AS lastID, percent AS lastPR, (SELECT Count(id) 
FROM myVIEW bigger 
WHERE bigger.percent > myv.percent) AS counter
FROM myVIEW myv 
Sign up to request clarification or add additional context in comments.

5 Comments

it works! thanks! but I have a strange Segmentation fault (core dumped)!
do you know why is the Segmentation ?
I have no ideas how a database system get segmentation fault. Are you using your own program to run the query? If so, we need check your code.
ok I put it in the edit. it is not the same parameters as before because now I put the real code copy paste
Check the size of my_cmd. You now have a.much longer query.
0

Use the following select query for creating your view

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.