This question already has answers here:
How to get min/max of two integers in Postgres/SQL?
(2 answers)
Closed 6 years ago.
is there some way to determine the max value out of two values in SQL?
I use the mod function:
MOD(cnt, cnt/100)
This yields a division by 0 error when cnt is smaller than 100. I therefore would like something like this:
MOD(cnt, MAX(cnt/100, 1))
You can use greatest
SELECT greatest(a, b, c) FROM your_table;
Related
This question already has answers here:
Get top results for each group (in Oracle)
(5 answers)
How to extract the first 5 rows for each id user in Oracle? [duplicate]
(2 answers)
First two salaries in each department [duplicate]
(3 answers)
Limit SQL query to only the top two counts per group [duplicate]
(1 answer)
Select top 15 records from each group [duplicate]
(2 answers)
Closed 12 months ago.
User requirement:- 2 policies in each product code with Highest (Maximum) SUM INSURED
How do I get 2 policies in each product code with Highest (Maximum) SUM INSURED
SELECT
PROD.MV_PREMIUM_REGISTER.T_DATE_DESC,
PROD.MV_PREMIUM_REGISTER.P_POLICY_NUMBER,
PROD.MV_PREMIUM_REGISTER.P_POLICY_STATUS,
PROD.MV_PREMIUM_REGISTER.VERSION,
PROD.MV_PREMIUM_REGISTER.P_RISK_INC_DATE,
PROD.MV_PREMIUM_REGISTER.P_OFFICE_LOC_ID,
PROD.MV_PREMIUM_REGISTER.LOCATION_DESC,
PROD.MV_PREMIUM_REGISTER.ZONE_DESC,
PROD.MV_PREMIUM_REGISTER.I_IMD_DESC,
PROD.MV_PREMIUM_REGISTER.P_SUB_IMD,
PROD.MV_PREMIUM_REGISTER.P_PRODUCT_ID,
PROD.MV_PREMIUM_REGISTER.P_RISK_EXPIRY_DATE,
PROD.MV_PREMIUM_REGISTER.P_GC_PLAN,
PROD.MV_PREMIUM_REGISTER.IMD_CHANNEL,
PROD.MV_PREMIUM_REGISTER.P_PRODUCT_DESC,
(PROD.MV_PREMIUM_REGISTER.SUM_INSURED) AS SUM_INSURED,
(PROD.MV_PREMIUM_REGISTER.GROSS_PREMIUM) AS GROSS_PREMIUM,
(PROD.MV_PREMIUM_REGISTER.STAMP_DUTY) AS STAMP_DUTY
FROM
PROD.MV_PREMIUM_REGISTER
WHERE
T_DATE_DESC BETWEEN '27-FEB-2022' AND '28-FEB-2022'
AND VERSION NOT LIKE '%E%'
AND LT_POLICY_YEAR = 1;
SELECT P_PRODUCT_ID,P_POLICY_NUMBER,SUM_INSURED from(
SELECT
PROD.MV_PREMIUM_REGISTER.P_PRODUCT_ID,
PROD.MV_PREMIUM_REGISTER.P_POLICY_NUMBER,
(PROD.MV_PREMIUM_REGISTER.SUM_INSURED) AS SUM_INSURED,
RANK() OVER(PARTITION BY P_PRODUCT_ID ORDER BY SUM_INSURED DESC) AS
RANK_COUNT
FROM
PROD.MV_PREMIUM_REGISTER
WHERE
T_DATE_DESC BETWEEN '27-FEB-2022' AND '28-FEB-2022'
AND VERSION NOT LIKE '%E%'
AND LT_POLICY_YEAR = 1) MVP where MVP.RANK_COUNT <3;
This question already has answers here:
What is the best way to create and populate a numbers table?
(12 answers)
Closed 4 years ago.
I am wondering if it is possible to get a query that will take a range of numbers, in this case 8 to 17, compare it against a field in a table and remove the ones that do appear in the table and return the rest?
I assume the peusdo code would look something like
Select nums from range(8-17) where nums not in (select column from table)
Is this possible at all?
Edit
To clarify my question.
In table I might have the following:
Intnumber
9
10
16
I would like to have the numbers between 8-17 that do not appear in this table, so 8,11,12,13,14,15,17
Kind regards
Matt
select nums from table where nums not between 8 and 17;
This question already has answers here:
SQL Server round after division
(2 answers)
Closed 5 years ago.
Is there any way to return 3 as a result of ((5168/2000) .
I'm using CEILING(5168/2000) to delete rows. Its returning 2. But I want 3.
So that loop execute for 3 times.
Is there any way to return 3 as a result of (5168/2000)
Yes, make sure you're diving floating point numbers not integers
CEILING(5168.0/2000)
One way to achive that, aside from hardcoding the .0 as I have above, is to cast your integer to an appropriate type, for example:
CEILING(CAST(5168 AS FLOAT)/2000)
or muultiply it by a decimal
CEILING((1.0 * 5168)/2000)
This question already has an answer here:
BigQuery check for array overlap
(1 answer)
Closed 5 years ago.
I have an array of values I'd like to filter results for if an array column contains any of these values, is there an easy way to perform an intersect in BigQuery using the standard SQL language?
This should give you the general direction:
SELECT ...
WHERE EXISTS(SELECT 1 FROM UNNEST(array_column) a WHERE a IN UNNEST(array_values))
This question already has answers here:
Counting chars in sequences via SQL
(2 answers)
Closed 7 years ago.
In Postgres/SQL, how can I get the count of a character in a column?
For example, I want to run a query which will return the number of times "X" appears in a column that has the value "XXX" - and it should return 3.
One method is the difference of lengths:
select (length(col) - length(replace(col, 'X', ''))) as NumX