The server-side language is PHP 7.0.
In general, I couldn't imagine what kind of solution I should take when I accomplished the subject matter, and I asked an unreasonable question.
However, after receiving comments from everyone, I can see some points that I don't understand.
The content obtained from SELECT is never limited to output from a single table, not all items in the table to be referenced, the function appropriately complements the items, and the number of columns cannot be predicted in the form of a row of a table.
If the columns are variable, the number of items and the name of the items to be retrieved from SQLServer should not be known, and if these are not captured, PHP might not be able to expand them to the table.
However, if I think about it carefully, it is clear that the output is fixed, and the number of items can be taken by COUNT or LENGTH, right?I feel like I can make it happen.
"When I looked at the ""additional note"" part, I was asked to express the ""row owner"" data (sales performance table by employee)" as the ""row owner"" data."
If you are referring to the
row ->row ->row ->row ->row ->
GROUP BY
and CASE
.(Same employee, change to SUM instead of MAX if the date has more than one track record)
Wouldn't it be possible to resolve SQL statements if they could dynamically create as many columns as needed (for example, PHP creates SQL statements with string combinations)?
SELECT
e.name
, MAX (CASE WHENs.sales_date='2018-07-05'THENs.amount ELSE NULL END) AS'2018-07-05'
, MAX (CASE WHENs.sales_date='2018-07-06'THENs.amount ELSE NULL END) AS'2018-07-06'
, MAX (CASE WHENs.sales_date='2018-07-07'THENs.amount ELSE NULL END) AS'2018-07-07'
, MAX (CASE WHENs.sales_date='2018-07-08'THENs.amount ELSE NULL END) AS'2018-07-08'
, MAX (CASE WHENs.sales_date='2018-07-09'THENs.amount ELSE NULL END) AS'2018-07-09'
, MAX (CASE WHENs.sales_date='2018-07-10'THENs.amount ELSE NULL END) AS'2018-07-10'
, MAX (CASE WHENs.sales_date='2018-07-11'THENs.amount ELSE NULL END) AS'2018-07-11'
from
sales ASs
JOIN
employees ASe
ON
s.employee_id=e.id
GROUP BY
s.employee_id
ORDER BY e.id
© 2024 OneMinuteCode. All rights reserved.