Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 20th, 2018 76 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. scala> sql("create table capacity (id String, capacity Int)");
  2. scala> sql("insert into capacity values ('A', 50), ('B', 100)");
  3. scala> sql("select * from capacity").show(false)
  4. +---+--------+
  5. |id |capacity|
  6. +---+--------+
  7. |A  |50      |
  8. |B  |100     |
  9. +---+--------+
  10.    
  11. scala> sql ("create table used (id String, capacityId String, used Int)");
  12. scala> sql ("insert into used values ('item1', 'A', 10), ('item2', 'A', 20), ('item3', 'A', 10), ('item4', 'B', 30), ('item5', 'B', 40), ('item6', 'B', 40)")
  13. scala> sql("select * from used order by capacityId").show(false)
  14. +-----+----------+----+
  15. |id   |capacityId|used|
  16. +-----+----------+----+
  17. |item1|A         |10  |
  18. |item3|A         |10  |
  19. |item2|A         |20  |
  20. |item6|B         |40  |
  21. |item4|B         |30  |
  22. |item5|B         |40  |
  23. +-----+----------+----+
  24.    
  25. +-----+----------+----+--------------+
  26. |id   |capacityId|used| capacityLeft |
  27. +-----+----------+----+--------------+
  28. |item1|A         |10  |40            |  <- 50(capacity of 'A')-10
  29. |item3|A         |10  |30            |  <- 40-10
  30. |item2|A         |20  |10            |  <- 30-20
  31. |item6|B         |40  |60            |  <- 100(capacity of 'B')-40
  32. |item4|B         |30  |30            |  <- 60-30
  33. |item5|B         |40  |-10           |  <- 30-40
  34. +-----+----------+----+--------------+
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top