Position relative

2 snippets across 2 stacks — HTML & CSS, SQL

Also written as relative position

HCHTML & CSS

Position Relative

HC · Layout & Positioning
syntax
position: relative;
top | right | bottom | left: value;
example
.badge-container {
  position: relative;
}

.badge {
  position: absolute;
  top: -8px;
  right: -8px;
}

Note position: relative keeps the element in the normal flow but enables offset with top/right/bottom/left. Its main use is establishing a positioning context for absolutely positioned children.

SQLSQL

PERCENT_RANK / CUME_DIST

SQL · Window Functions
syntax
PERCENT_RANK() OVER (ORDER BY column)
CUME_DIST() OVER (ORDER BY column)
example
SELECT
  first_name,
  salary,
  PERCENT_RANK() OVER (ORDER BY salary) AS pct_rank,
  CUME_DIST() OVER (ORDER BY salary) AS cumulative_dist
FROM employees;
output
-- first_name | salary | pct_rank | cumulative_dist
-- Dave       | 50000  | 0.00     | 0.25
-- Carol      | 65000  | 0.33     | 0.50
-- Bob        | 82000  | 0.67     | 0.75
-- Alice      | 95000  | 1.00     | 1.00

Note PERCENT_RANK returns (rank - 1) / (total - 1), ranging from 0 to 1. CUME_DIST returns the fraction of rows with values less than or equal to the current row. Both are useful for percentile analysis.