1
SELECT OlineDate, OlineOrder, OlineDesc, OlineGroup, OlinePrice
FROM tblorderlines
WHERE DATE(OlineDate) = '2019-10-19' AND OlineOrder = 170
AND OlineGroup IN ('spec')

|====================================================================|
| OlineOrder |OlineDate   | OlineDesc | OlineGroup     | OlinePrice  |
|============+============+===========+================+=============|
| 10         | 2019-10-19 | Coupon    |    spec        |   -2.42     |
|------------+------------+-----------+----------------|-------------|
| 10         | 2019-10-19 | 10% OFF   |    spec        |    0.00     |
|------------+------------------------+----------------+-------------|

I am looking for a query that would interchange the '10% off' value over the 'Coupon' value. The only results I've found that may produce the result I want are pivot tables but those don't exist in MySQL. Is there another route I can take?

codenoob9000
  • 47
  • 1
  • 7
  • what will be the criteria for replace? If it's fixed values why not use [Mysql Replace](http://www.mysqltutorial.org/mysql-replace.aspx) – Farooq Ahmed Khan Oct 21 '19 at 18:40
  • See https://stackoverflow.com/questions/12004603/mysql-pivot-row-into-dynamic-number-of-columns for how to do pivot in MySQL. – Barmar Oct 21 '19 at 18:51
  • The OlineDesc column can be whatever discount name is setup so it will never be a static value. Essentially I am trying to generate a report that will track discount amounts per discount. The problem is the way the XML is generated, it has a generic 'Coupon' line and the discount amount (OlinePrice) is associated with that. The next line, in this example 10% Off, is the actual discount name. – codenoob9000 Oct 21 '19 at 18:53

0 Answers0