SQL累积计数(SQL Cumulative Count)
我有部门的桌子。 我需要计算有多少人在哪个部门。 这很容易通过
SELECT DEPT, COUNT(*) as 'Total' FROM SR GROUP BY DEPT;
现在我还需要做如下累计计数:
我发现一些SQL来计算运行总数,但不是这样的情况。 请问在这种情况下你能提供一些建议吗?
I have table with departments. I need to count how many people are within which dept. This is easily done by
SELECT DEPT, COUNT(*) as 'Total' FROM SR GROUP BY DEPT;
Now I need to also do cumulative count as below:
I have found some SQL to count running total, but not case like this one. Could you provide me some advice in this case, please?
原文:https://stackoverflow.com/questions/19361337
最满意答案
您可以在代码中考虑两件事:
行
NSString *FileNamePath = [[NSBundle mainBundle] pathForResource:@"testAudio" ofType:@"aiff"];
不需要,因为它只返回文件的完整路径,而你只需要它的最后一部分:“testAudio.aiff”您构造URL对象,构造函数接受具有有效协议前缀的字符串,如“http://”或“ftp://”,而您需要另一个名为
initFileURLWithPath:
构造函数。因此,以上所有代码可能如下所示:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *appSettingsPath = [documentsDirectory stringByAppendingPathComponent:@"testAudio.aiff"]; NSURL *url=[[NSURL alloc]initFileURLWithPath:appSettingsPath]; BOOL result = [MyAcaTTS_ startSpeakingString:@"testing" toURL:url];
There are two things for you to consider in your code:
The line
NSString *FileNamePath = [[NSBundle mainBundle] pathForResource:@"testAudio" ofType:@"aiff"];
is not required since it returns full path of the file while you need only the last part of it: "testAudio.aiff"You construct URL object with constructor accepting strings with valid protocol prefix, like "http://" or "ftp://" while your need another constructor named
initFileURLWithPath:
instead.So with all the above your code may look like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *appSettingsPath = [documentsDirectory stringByAppendingPathComponent:@"testAudio.aiff"]; NSURL *url=[[NSURL alloc]initFileURLWithPath:appSettingsPath]; BOOL result = [MyAcaTTS_ startSpeakingString:@"testing" toURL:url];
相关问答
更多-
使用NSURL访问本地文件(Accessing Local file using NSURL)[2022-01-29]
这也可以工作: NSString *path = [[NSBundle mainBundle] pathForResource:@"XMLTest" ofType:@"xml"]; 希望这可以帮助! This would also work: NSString *path = [[NSBundle mainBundle] pathForResource:@"XMLTest" ofType:@"xml"]; Hope this helps! -
NSURL确实有这样的方法: - (BOOL)checkResourceIsReachableAndReturnError:(NSError **)error 哪个“返回文件URL指向的资源是否可以到达”。 NSURL *theURL = [NSURL fileURLWithPath:@"/Users/elisevanlooij/nonexistingfile.php" isDirectory:NO]; NSError *err; if ([theURL checkReso ...
-
你在设置什么AudioSession类别? 如果您不是,请参阅此文档: 音频会话类别 如果您将会话设置为AVAudioSessionCategoryAmbient ,我相信您应该获得所需的行为: 应用程序的类别,其中声音播放是非主要的 - 也就是说,您的应用程序可以在声音关闭时成功使用。 此类别也适用于“播放”风格的应用程序,例如用户在播放音乐应用程序时播放的虚拟钢琴。 使用此类别时,来自其他应用程序的音频会与您的音频混合。 屏幕锁定和静音开关(在iPhone上称为Ring / Silent开关)可以使您的 ...
-
将音频文件保存到NSURL(save audio file to NSURL)[2022-07-21]
您可以在代码中考虑两件事: 行NSString *FileNamePath = [[NSBundle mainBundle] pathForResource:@"testAudio" ofType:@"aiff"]; 不需要,因为它只返回文件的完整路径,而你只需要它的最后一部分:“testAudio.aiff” 您构造URL对象,构造函数接受具有有效协议前缀的字符串,如“http://”或“ftp://”,而您需要另一个名为initFileURLWithPath:构造函数。 因此,以上所有代码可能如下所示: ... -
xcode:如何使用AVFoundation录制音频后保存音频文件(xcode: How to save audio file after recording audio using AVFoundation)[2022-10-24]
您需要停止录制才能将数据永久保存到文件中: [recorder stop]; You need to stop recording in order to save the data to the file permanently: [recorder stop]; -
我强烈建议您将保存的字段特定处理更改为自定义字段,从FileField扩展。 问题是你正试图保存一个gTTS的实例。 试试下面的代码: import tempfile from django.core.files import File from django.db import models class Word(models.Model): word = models.CharField(max_length=200) audio = models.FileField(upload ...
-
NSBundle *mainBundle = [NSBundle mainBundle]; NSString *myFile = [mainBundle pathForResource: @"audio" ofType: @"m4a"]; NSURL *audioFileURL = [NSURL URLWithString:myFile]; 并检查Build Phases" -> "copy bundle Resources"是否存在该文件Build Phases" -> "copy bundle Res ...
-
您必须将URL转换为路径字符串,通过将扩展名与完整路径分开来将其拆分,然后使用附加的_SubCap扩展名重新构建它。 码: NSString *subCapString = .... // string to write to _SubCap.txt file NSString *path = selectedFile.path; NSString *extension = path.pathExtension; NSString *strippedPath = [path stringByDeleting ...
-
是否可以在App沙箱外的iOS上保存录制的音频文件?(Is it possible to save a recorded audio file on iOS outside the App sandbox?)[2022-07-18]
不,这在iOS 8之前是不可能的。你做得对。 您需要在应用沙箱中保存音频。 解决方法是将音频文件转换为视频文件,但这不是一个胜利。 No, this is not possible till iOS 8. You are doing it right. You need to save the audio in your app sandbox. Work around can be converting audio file to video file, but that is not a win. -
最后想出来了。 我进行了以下更改以使其工作: 1)我使用fileURLWithPath而不是URLWithString,如下所示: NSURL *assetURL = [NSURL fileURLWithPath:passURL]; AVURLAsset *asset = [AVURLAsset assetWithURL:assetURL]; 2)在我保存音频文件URL之前,我把它保存为NSString,如下所示: 文件:///var/mobile/Containers/Data/Application/ ...