如何将此 SQL 代码转换为 Power Apps?

发布于 2025-01-11 13:02:41 字数 816 浏览 2 评论 0原文

我有一个 SQL 查询,它显示数据库中某个组的最新记录。为了获取每个组的最新记录,我使用 ID 列,它是一个自动增量列。最高的 ID 号将是最新的记录。

但是,我无法将其转换为 Power Apps 库中的类似代码。

SELECT        *
-- from my table
FROM            dbo.MyTable
-- where ID is the maximum ID grouped by product_ID
WHERE        (ID IN
                             (SELECT        MAX(ID)
                               FROM            dbo.MyTable
                               GROUP BY product_ID))

and Product_Type = 'Vegetables'

我的尝试,接近了吗?

ForAll(    
    GroupBy(
        SortByColumns(
            Filter(MyTable, Product_Type ='Vegetables'),
            'product_ID', Ascending, 'ID', Descending),
        'product_ID', '_recs'
    ),
    Patch(First(_recs), {product_ID: product_ID})
)

我知道其中一些功能不可“委托”,这可能是问题所在。

I have a SQL query that shows me the latest record for a group in my database. To get the latest record for each group, I use the ID column, which is an auto-increment column. The highest ID number will be the latest record.

However I cannot convert this to a similar code in Power Apps gallery.

SELECT        *
-- from my table
FROM            dbo.MyTable
-- where ID is the maximum ID grouped by product_ID
WHERE        (ID IN
                             (SELECT        MAX(ID)
                               FROM            dbo.MyTable
                               GROUP BY product_ID))

and Product_Type = 'Vegetables'

My attempt, is it close?

ForAll(    
    GroupBy(
        SortByColumns(
            Filter(MyTable, Product_Type ='Vegetables'),
            'product_ID', Ascending, 'ID', Descending),
        'product_ID', '_recs'
    ),
    Patch(First(_recs), {product_ID: product_ID})
)

I understand some of these functions are not "delegable" which may be the issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很坚强 2025-01-18 13:02:41

试试

Distinct(
  MyTable,
  product_id
).Result

这个应该会给你一个所有唯一产品 ID 的数组。
现在,如果您将其放在图库上,您可以向每行添加一个标签,其中显示带有默认文本值的文本标签:

First(
SortByColumns(
  Filter(
    MyTable,
    product_id=ThisItem.product_id
  ),
  "ID",
  "Descending"
  )
).ID

基本上,您获取产品 ID 并查找每行的最大 ID。

有多个选项,这可能需要一些调整,但这将帮助您入门。

Try

Distinct(
  MyTable,
  product_id
).Result

This should give you an array of all unique product id's.
Now, if you place it on a gallery, you can add a label to each row where you display a text label with the default text value:

First(
SortByColumns(
  Filter(
    MyTable,
    product_id=ThisItem.product_id
  ),
  "ID",
  "Descending"
  )
).ID

Basically, you take the product ID's and look up the max ID for every row.

There are multiple options, and this might need some tweaking, but this will get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文