首页 \ 问答 \ SELECT作为另一个SELECT的别名(SELECT as alias to another SELECT)

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 table tags I have id, personid, tag

And 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
更新时间:2023-09-14 14:09

最满意答案

你可以这样做:( 忽略这个)

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>

相关问答

更多

相关文章

更多

最新问答

更多
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 武陟会计培训类的学校哪个好点?
  • Spring事务管理:无法解析bean'transactionManager'的引用(Spring transaction management: Cannot resolve reference to bean 'transactionManager')
  • 无法在后面访问链接:焦点,移开,div(Link can't be accessed behind :focus, moved out of the way, div)
  • 总和形式选择值 - 我做错了什么(sum form select values - what am I doing wrong)
  • DocBook5 ISO 690参考书目的文档[关闭](Documentation for DocBook5 ISO 690 bibliography [closed])
  • 为什么改变所有点的颜色而不是一个?(Why changed the color for all points instead of one?)
  • 如何从字符串中删除所有尾部破折号?(How can I remove all trailing dashes from a string?)
  • 有没有办法以这种方式调用这个JavaScript函数?(is there a way to call this javascript function in this way?)
  • 在更换字符串时替换组(Replacing a group while replacing a string)
  • 如何用Dreamweaver制作网页表格
  • git:如何能够再次切换分支(git: how to be able to switch branches again)
  • 应用程序在打印联系人姓名和号码时崩溃(app crashes in the middle of printing contact names and numbers)
  • 用CSS @media查询目标移动设备解决方案的最准确的方法是什么?(what is the most accurate way to query target mobile device resolutions with CSS @media?)
  • Java - 如何仅使元音加倍(Java - How to double only Vowels)
  • 调用root.destroy()后出现“tkinter.TclError:invalid command name”错误(“tkinter.TclError: invalid command name” error after calling root.destroy())
  • 使用键绑定在两个表单之间切换(Switching between two forms with Key Bindings)
  • 我把正确的导入但错误仍然发生在Hibernate 5中的org.hibernate.MappingException(I put the correct import but the error still happen org.hibernate.MappingException in Hibernate 5)
  • 从宁波江北洪塘到宁波南站人力市场乘坐什么车子要转什么车子,我去人力市场考电工上岗证
  • jQuery - 用所有元素的新值替换属性值(jQuery - replace attribute value with new value of all elements)
  • Lenovo Low Profile USB Keyboard 下载后找不到电脑上没有
  • 将反应元素渲染到隐藏区域以进行测量(Render a react element to a hidden area for measurement)
  • 有没有可能确定iOS widget何时隐藏?(Is it possible to determine when iOS widget hides?)
  • 量角器 - 描述没有定义(Protractor - describe is not defined)
  • Jackson序列化:XML和JSON的不同格式(Jackson Serialization: Different formats for XML and JSON)
  • 在Javascfipt中解析XML(Parsing XML in Javascfipt)
  • Firebird客户端安装(Firebird client installation)
  • 在未安装XML DB的情况下从Oracle发送电子邮件(Send email from Oracle without XML DB installed)