How to get a minimum value for each entry in the string in sql IN statement?

Aditya_Anand

I am trying to get the minimum value for each string element but I am always getting the minimum of all the values that I get after querying the sql.

QUERY

SELECT `assigned_to`,`appointment_lat`,`appointment_long`,`appointment_time` 
FROM `tb_schedules` 
WHERE `assigned_to` IN (26,27) 
AND ( appointment_time>'2014-09-23 07:33:00' ) 
GROUP BY `assigned_to` 
ORDER BY (DATEDIFF('2014-09-23 07:33:00',`appointment_time`)) 
LIMIT 1
Bohemian

If I understand your question correctly, you want the next appointment to a for each id listed:

SELECT * FROM (
SELECT `assigned_to`,`appointment_lat`,`appointment_long`,`appointment_time` 
FROM `tb_schedules` 
WHERE `assigned_to` IN (26,27) 
AND appointment_time> now()
ORDER BY 4) x
GROUP BY `assigned_to`

This query makes use of mysql's non-standard group by capability, where if you don't specify all non-aggregate columns, it will pick one row for each unique grouped value(s) - according to the docs it's a random row, but in reality it is reliably the first row, so ordering before grouping gives you a predicable row.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

SQL statement - get 1st minimum then 2nd minimum from join

分類Dev

How to get an integer value from Entry in Tkinter?

分類Dev

minimum value for each unique id

分類Dev

How to get the value from include statement in a variable?

分類Dev

How to replace the column value in select statement in Sql?

分類Dev

How to get a single row for each customer based on highest value in another column in SQL Server

分類Dev

SQL: How to get result set containing single record for each user with existing value

分類Dev

How to make a for loop iterate through each item in a string with an if statement?

分類Dev

How to get each checkbox textfield value

分類Dev

Python - Cant get minimum value

分類Dev

Get minimum value in linq query

分類Dev

Update row with minimum value sql

分類Dev

Get HIGHEST and SECOND HIGHEST value for each ID (SQL)

分類Dev

SQL to get the first occurence of a value in each column within grouped elements

分類Dev

SQL - for each entry in a table - check for associated row

分類Dev

How to write a SQL statement to return all children of each root,extend to each root

分類Dev

How to get a string value such as R.string.value in a ViewModel

分類Dev

How to divide a string value by another string value, each containing a numeric value

分類Dev

Creating a LINQ statement from this SQL to get the latest edit of each original record in the database

分類Dev

Get the Minimum value from Consecutive dataframe values

分類Dev

How to get a string value from an EditText in RecyclerView?

分類Dev

How to get a value from Select-String

分類Dev

PL/SQL select the minimum value of a vector

分類Dev

How to join an array of values by returning each value as a separate string?

分類Dev

How to get each value inside <li> with <span> tag BeautifulSoup

分類Dev

How to filter and get each object key's value using startsWith?

分類Dev

How to get value of last valid index of a different column for each row

分類Dev

How to get the value for each seek bar created in list view Android?

分類Dev

SQL query to get the record which is not a maximum or a minimum

Related 関連記事

  1. 1

    SQL statement - get 1st minimum then 2nd minimum from join

  2. 2

    How to get an integer value from Entry in Tkinter?

  3. 3

    minimum value for each unique id

  4. 4

    How to get the value from include statement in a variable?

  5. 5

    How to replace the column value in select statement in Sql?

  6. 6

    How to get a single row for each customer based on highest value in another column in SQL Server

  7. 7

    SQL: How to get result set containing single record for each user with existing value

  8. 8

    How to make a for loop iterate through each item in a string with an if statement?

  9. 9

    How to get each checkbox textfield value

  10. 10

    Python - Cant get minimum value

  11. 11

    Get minimum value in linq query

  12. 12

    Update row with minimum value sql

  13. 13

    Get HIGHEST and SECOND HIGHEST value for each ID (SQL)

  14. 14

    SQL to get the first occurence of a value in each column within grouped elements

  15. 15

    SQL - for each entry in a table - check for associated row

  16. 16

    How to write a SQL statement to return all children of each root,extend to each root

  17. 17

    How to get a string value such as R.string.value in a ViewModel

  18. 18

    How to divide a string value by another string value, each containing a numeric value

  19. 19

    Creating a LINQ statement from this SQL to get the latest edit of each original record in the database

  20. 20

    Get the Minimum value from Consecutive dataframe values

  21. 21

    How to get a string value from an EditText in RecyclerView?

  22. 22

    How to get a value from Select-String

  23. 23

    PL/SQL select the minimum value of a vector

  24. 24

    How to join an array of values by returning each value as a separate string?

  25. 25

    How to get each value inside <li> with <span> tag BeautifulSoup

  26. 26

    How to filter and get each object key's value using startsWith?

  27. 27

    How to get value of last valid index of a different column for each row

  28. 28

    How to get the value for each seek bar created in list view Android?

  29. 29

    SQL query to get the record which is not a maximum or a minimum

ホットタグ

アーカイブ