Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MySQL, how to repeat same line x times
  2. SELECT ordernumber
  3.   , article_description
  4.   , article_size_description
  5.   , concat(NumberPerBox,' pieces') as contents
  6.   , NumberOrdered
  7. FROM customerorder
  8. WHERE customerorder.id = 1;
  9.        
  10. Boxnr   Ordernr        as_description   contents   NumberOrdered
  11. ------+--------------+----------------+-----------+---------------
  12.   1   | CORDO1245    | Carrying bags  | 2,000 pcs | 50,000
  13.   2   | CORDO1245    | Carrying bags  | 2,000 pcs | 50,000
  14. ....
  15.   25  | CORDO1245    | Carrying bags  | 2,000 pcs | 50,000
  16.        
  17. SELECT
  18.    IV.number as Boxnr
  19.   ,ordernumber  
  20.   ,article_description
  21.   ,article_size_description
  22.   ,concat(NumberPerBox,' pieces') as contents
  23.   ,NumberOrdered
  24. FROM
  25.   customerorder
  26.   INNER JOIN (
  27.     SELECT
  28.        Numbers.number
  29.       ,customerorder.ordernumber
  30.       ,customerorder.NumberPerBox
  31.     FROM
  32.       Numbers
  33.       INNER JOIN customerorder
  34.         ON Numbers.number BETWEEN 1 AND customerorder.NumberOrdered / customerorder.NumberPerBox
  35.     WHERE
  36.       customerorder.id = 1
  37.     ) AS IV
  38.     ON customerorder.ordernumber = IV.ordernumber