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;
SQL SELECT statement can be used along with COUNT(*) function to count and display the data values. The COUNT(*) function represents the count of all rows present in the table (including the NULL and NON-NULL values).
COUNT(*) The COUNT(*) function returns the number of rows in a dataset using the SELECT statement. The function counts rows with NULL, duplicate, and non-NULL values. You can also use the WHERE clause to specify a condition.
COUNT(*) returns the number of rows in a specified table, and it preserves duplicate rows. It counts each row separately. This includes rows that contain null values.
As you've already learned, COUNT(*) will count all the rows in the table, including NULL values. On the other hand, COUNT(column name) will count all the rows in the specified column while excluding NULL values.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With