SELECT作为另一个SELECT的别名(SELECT as alias to another SELECT)
我有一个关系“一对多”的两个表。
所以在表格中我有id,name等,在表格
tags
我有id,personid,tag一个人可以拥有N个带有不同标签的条目。
我以为我可以做点什么
SELECT id, name, (SELECT * FROM tags WHERE personid = id) AS tags FROM person
我希望收到一个包含NUMBER(id) , STRING(name) , ARRAY(tags)的结果行。 我知道如何使用for循环执行此操作,使用2个单独的查询,但我认为MySQL应该最好这样做。
如果我做一个JOIN我最后会有很多行,我想把所有标签分组在每行的数组类似的条目中,即。 每人一排。
这可能吗?
I have two tables in a relation "one to many".
So in table
person
I have id, name, etc and in tabletags
I have id, personid, tagAnd one person can have N entries with different tags.
I thought I could do something like
SELECT id, name, (SELECT * FROM tags WHERE personid = id) AS tags FROM person
And I expect to receive a result row with NUMBER(id), STRING(name), ARRAY(tags). I know how to do this with a for loop, with 2 separate queries but I think MySQL should be best to do this.
If I do a JOIN I end up with many rows, bu I want to group all tags in a array-like entry of each row I get, ie. one row per person.
Is this possible?
原文:https://stackoverflow.com/questions/36662121
最满意答案
你可以这样做:( 忽略这个)
int millis = 500; new Handler().postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(SplashScreenActivity.this, HomeActivity.class)); SplashScreenActivity.this.finish(); } }, millis);
更新1(应该可以):在你的MainActivity中尝试这个,你的计算时间错误,所以使用日历。 如果它有效,我会尝试解释。
Intent intent = new Intent(this, Receiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0); //Or you can get broadcast in your way. int seconds = 25; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND, seconds); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
更新2:您应该在清单中注册您的接收器。 在某些情况下,接收器上有意图过滤器,但我应该这样工作。 确保包裹和接收器的名称正确无误。
<application ...> <activity ...> ... <receiver android:name=".package.YourReceiver"> </receiver> ... </application>
You can do something like this: (ignore this one)
int millis = 500; new Handler().postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(SplashScreenActivity.this, HomeActivity.class)); SplashScreenActivity.this.finish(); } }, millis);
Update 1 (should work): Try this in your MainActivity, your probably counting time in wrong way so use calendar. If it works, I'll try to explain.
Intent intent = new Intent(this, Receiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0); //Or you can get broadcast in your way. int seconds = 25; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND, seconds); alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
Update 2: You should register your receiver in the manifest. In some cases there are intent filters on receivers but I it should work like that. Be sure that name of your package and receiver are correct.
<application ...> <activity ...> ... <receiver android:name=".package.YourReceiver"> </receiver> ... </application>
相关问答
更多-
接收器仅接收广播。 只有一个活动属于启动器。 意图和过滤器解释了很多这方面的内容。 要创建一个不可见的活动(在你快速完成时看不到它),用这个主题声明它: @android:style/Theme.Translucent.NoTitleBar 但是如果你有一个不可见的活动(为了避免混淆用户),你最好还添加以下内容: android:noHistory="true" A Receiver receives broadcasts only. Only an activity belongs in the la ...
-
解决方法是使用WakeLock如下“ @Override public void onReceive(Context context, Intent intent) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.PARTIA ...
-
使用BroadcastReceiver在几秒钟后启动新活动(Start new Activity after few seconds with BroadcastReceiver)[2023-07-04]
你可以这样做:( 忽略这个) int millis = 500; new Handler().postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(SplashScreenActivity.this, HomeActivity.class)); SplashScreenActivity.this.finish(); } ... -
发送广播很弱。 活动必须直接从服务内部开始。 而不是这个: Intent broadcastIntent = new Intent(); broadcastIntent.setAction(DataBroadcastReceiver.ACTION_RESP); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); sendBroadcast(broadcastIntent); 在服务中使用此: Intent intent ...
-
从BroadcastReceiver或Service Class启动新活动(Start new Activity From BroadcastReceiver or Service Class)[2023-08-03]
虽然我不能为你的第一个问题提供解决方案,但我会回答第二个问题。 @Override public void onReceive(Context context, Intent intent) { Intent intent = new Intent(context, SampleService.class); context.getApplicationContext().startService(intent); } 此外,Android SDK开发人员不建议从广播接收器或 ... -
Fragment和BroadcastReceiver会在几秒钟后冻结应用程序(Fragment and BroadcastReceiver freeze app after some seconds)[2021-09-06]
根本原因 我认为您正在使用第三方库来检测位置。 图书馆以非常高的速度接收GPS坐标。 然后,您的广播接收器将接收这些坐标。 你的广播接收器正在UI线程上工作。 你的应用程序冻结的原因是因为UI线程以非常高的速度工作。 解 您的问题的解决方案在于绑定服务。 您可以在android开发人员文档绑定服务中找到代码示例。 对于像音乐播放器这样的用例,媒体在后台线程中播放,但播放音乐的持续时间显示在用户界面上,绑定服务可能很有用。 我希望这能让你朝着正确的方向前进。 Root Cause I think you ar ... -
如何在没有被杀或失踪的情况下听取这些意图? 你没有。 您重写您的应用程序要么不使用这些广播,要么在丢失广播的情况下更具弹性。 毕竟,它不只是“Android杀死我的服务来释放一些RAM,然后重新启动它”,但任务管理器等可以摆脱你的服务。 How could I listen to those intents without being killed or missing some? You don't. You rewrite your app to either not use those broadca ...
-
愿这帮助你... 创建名为AutoStart.class类 public class AutoStart extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if (intent.getAction().equals(Intent.ACTION_BOOT_ ...
-
Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())[2022-03-20]
该文件意味着如果您在onPause()中取消注册,那么在暂停时您将不会收到广播意图。 如果您没有注册,那么您将继续接收广播意图。 你在onDestroy()中取消注册,但是当按下home键时,只调用onStop()并且不会调用onDestroy()。 因此,您继续接收广播。 The document meant to say that if you unregistered in onPause() then you won't receive broadcast intents when paused. ... -
@Override public void onReceive(Context context, Intent intent){ Context appContext = context.getApplicationContext(); 使用appContext您可以启动“正常”活动。 这里描述的是一个例子 public void sendNotificationEmail(String emailBody) { Intent emailIntent = new Intent(In ...