· 8 years ago · Sep 02, 2018, 03:46 AM
1How to dynamically name new column resulting after query according to a specific column value (say some id )existing in table
2CREATE TABLE IF NOT EXISTS `powergenerationdatapoint` (
3 `id` bigint(20) NOT NULL AUTO_INCREMENT,
4 `current` double DEFAULT NULL,
5 `timestamp` datetime DEFAULT NULL,
6 `voltage` double DEFAULT NULL,
7 `solarpanel_id` bigint(20) DEFAULT NULL,
8 PRIMARY KEY (`id`),
9 KEY `FK8D91D4A9BBD00242` (`solarpanel_id`)
10) ;
11
12select avg(current*voltage) as (columnname according to solarpanel_id) where solarpanel_id=?