我一直在寻找这个,但没有雪茄.烟雾开始从我的耳朵里冒出来.请帮忙
如何将两个表中的两列相加并按用户ID分组?
有两张桌子.
Recipe Table
recipeid userid recipe_num_views
Meals Table
mealsid userid meal_num_views
Run Code Online (Sandbox Code Playgroud)
目标是按用户标识对表和组中的num视图求和
so for example
Recipe Table
1 3 4
2 4 6
Meal Table
1 3 2
2 4 5
select sum(recipe views)+sum(meal views)
WHERE recipe.userid=meals.userid GROUP BY userid
Run Code Online (Sandbox Code Playgroud)
应该给
userid=3 , sum=6
userid=4, sum=11
Run Code Online (Sandbox Code Playgroud)
这给了一个更大的数字.
我尝试使用PHPExcel手册的4.2.1节中的不同缓存方法.
做了100k行的基准测试,这是结果
gzip = time=50,memoryused=177734904
ser = time=34,memoryused=291654272
phptm= time=41,memoryused=325973456
isamm= time=39,memoryused=325972824
Run Code Online (Sandbox Code Playgroud)
手册说phptmp和isamm方法使用磁盘而不是内存.因此,他们应该使用最少的记忆,但似乎这是相反的.
这是我用来测试的代码:
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
// $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized;
// $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;
// $cacheSettings = array( 'memoryCacheSize' => '8MB');
// $cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_discISAM;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$xlsReader = PHPExcel_IOFactory::createReader($fileType);
$xlsReader->setReadDataOnly(true);
Run Code Online (Sandbox Code Playgroud)
任何人都可以阐明这个谜团吗?
我试图读取一个单元格,其中可能有尾随零作为字符串而不是数字(剥离前导零).正如此答案所示,单元格由整数列/行读取,而不是列字符串.
初始代码
$instReader = $reader->load($this->file);
$sheet = $instReader->getSheet(0);
Run Code Online (Sandbox Code Playgroud)
我试过修改这个:
$keyCell = $sheet->getCellByColumnAndRow(1,5);
Run Code Online (Sandbox Code Playgroud)
至:
$sheet->setCellValueExplicitByColumnAndRow(1,5, PHPExcel_Cell_DataType::TYPE_STRING);
$keyCell = $sheet->getCellByColumnAndRow(1,5);
Run Code Online (Sandbox Code Playgroud)
前者为$ keyCell而不是01407提供1407
后者给出"s"或""
在调用getCellByColumnAndRow并仅使用列和行的整数值之前,如何将单元格视为字符串.
(顺便说一句,如果这可以针对整个列进行一次,而不是每次针对每个单独的单元格做得更好)