vault backup: 2026-03-31 16:53:06
This commit is contained in:
@@ -9,6 +9,8 @@ dg-publish: true
|
||||
---
|
||||
# 2025-12-17 05:39:??
|
||||
|
||||
%% [[statistical-modeling-for-construction-estimating]] %%
|
||||
|
||||
One aspect of estimating that I find most interesting,
|
||||
but that is criminally understudied,
|
||||
is the effect of building dimensions
|
||||
|
||||
@@ -21,8 +21,76 @@ yearly: "[[2026]]"
|
||||
|
||||
### Cross Join
|
||||
|
||||
[](https://www.sqlshack.com/sql-cross-join-with-examples/)
|
||||
In [[sql]], the `CROSS JOIN` operation
|
||||
returns the [cartesian product](https://en.wikipedia.org/wiki/Cartesian_product)
|
||||
of two tables.
|
||||
|
||||
### ~~add column, update by key~~
|
||||
```sqlite
|
||||
CREATE TABLE WireSizes (wire_size TEXT NOT NULL);
|
||||
INSERT INTO WireSizes VALUES ('#12'), ('#10'), ('#8'), ('#6'), ('#4'), ('#2'), ('#1'), ('#1/0'), ('#2/0');
|
||||
|
||||
CREATE TABLE WireMaterials (wire_material TEXT NOT NULL);
|
||||
INSERT INTO WireMaterials VALUES ('CU'), ('AL');
|
||||
|
||||
SELECT wire_size, wire_material
|
||||
FROM WireSizes
|
||||
CROSS JOIN WireMaterials;
|
||||
```
|
||||
|
||||
```sqlite
|
||||
SELECT wire_size||' '||wire_material AS wire_type
|
||||
FROM WireSizes, WireMaterials; -- implicit cross join
|
||||
```
|
||||
|
||||
### Create Table From Query
|
||||
|
||||
`CREATE TABLE _ AS` syntax is intuitive,
|
||||
|
||||
```sqlite
|
||||
CREATE TABLE Wires AS
|
||||
SELECT wire_size, wire_material
|
||||
FROM WireSizes, WireMaterials;
|
||||
```
|
||||
|
||||
but it excludes the ability to set constraints.
|
||||
|
||||
Use this pattern instead:
|
||||
|
||||
```sqlite
|
||||
CREATE TABLE Wires (
|
||||
wire_size TEXT NOT NULL,
|
||||
wire_material TEXT NOT NULL,
|
||||
PRIMARY KEY (wire_size, wire_material),
|
||||
FOREIGN KEY (wire_size) REFERENCES WireSizes(wire_size),
|
||||
FOREIGN KEY (wire_material) REFERENCES WireMaterials(wire_material)
|
||||
);
|
||||
|
||||
INSERT INTO Wires (wire_size, wire_material)
|
||||
SELECT wire_size, wire_material
|
||||
FROM WireSizes, WireMaterials;
|
||||
```
|
||||
|
||||
You'd think you could just throw an `AS` after the constraints
|
||||
and omit the `INSERT` statement, but no.
|
||||
|
||||
### Add Columns to Table
|
||||
|
||||
for adding data after creating new tables with [[#Cross Join]]
|
||||
|
||||
```sqlite
|
||||
ALTER TABLE Wires
|
||||
ADD length_specific_dc_resistance_in_milliohms_per_foot FLOAT;
|
||||
|
||||
UPDATE Wires
|
||||
SET length_specific_dc_resistance_in_milliohms_per_foot = CASE
|
||||
WHEN wire_size = '#8' AND wire_material = 'CU' THEN 0.778
|
||||
WHEN wire_size = '#6' AND wire_material = 'CU' THEN 0.491
|
||||
WHEN wire_size = '#4' AND wire_material = 'CU' THEN 0.308
|
||||
-- ...
|
||||
ELSE NULL
|
||||
END;
|
||||
```
|
||||
|
||||
### Resources
|
||||
|
||||
* [sqlshack.com](https://www.sqlshack.com/)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
id: 2026-03-31T14:53:42-04:00
|
||||
aliases: []
|
||||
title: 2026-03-31 14:53:42
|
||||
tags:
|
||||
- authorship/original
|
||||
- destiny/permanent
|
||||
- status/draft
|
||||
- type/periodic/timestamped
|
||||
dg-publish: true
|
||||
date-created: 2026-03-31T14:53:42-04:00
|
||||
daily: "[[2026-03-31]]"
|
||||
weekly: "[[2026-W14]]"
|
||||
monthly: "[[2026-03]]"
|
||||
quarterly: "[[2026-Q1]]"
|
||||
yearly: "[[2026]]"
|
||||
---
|
||||
# 2026-03-31 14:53:42
|
||||
|
||||
%% [[statistical-modeling-for-construction-estimating]] %%
|
||||
|
||||
A while ago I wrote proofs
|
||||
for average distance between random points
|
||||
under taxicab geometry.
|
||||
|
||||
I ought to find those and add them to the vault.
|
||||
|
||||
One condition I know I didn't examine
|
||||
was random points on the perimeter of a rectangular space.
|
||||
This would be ideal for runs between equipment in the same room.
|
||||
Reference in New Issue
Block a user