distinct

laravel 5 - paginate total() of a query with distinct

廉价感情. 提交于 2019-12-12 06:12:58
问题 I have a query to get photos according to values in a pivot table, that stores the relation of "pics" and "tags": #photos $q = PicTag::select(DB::raw('distinct(pics.id)'), 'pics.url', 'pics.titel', 'pics.hits', 'pics.created_at', 'users.username', 'users.displayname') ->leftJoin('pics', 'pics.id', '=', 'pic_tag.pic_id') ->leftJoin('users','users.id','=','pics.user_id') ->whereIn('pic_tag.tag_id', $tagids); if($cat) $q->where('typ',$cat); if($year) $q->where('jahrprod',$year); $pics = $q-

Hive: How to do a SELECT query to output a unique primary key using HiveQL?

不羁的心 提交于 2019-12-12 03:46:16
问题 I have the following schema dataset which i want to transform into a table that can be exported to SQL. I am using HIVE . Input as follows call_id,stat1,stat2,stat3 1,a,b,c, 2,x,y,z, 3,d,e,f, 1,j,k,l, The output table needs to have call_id as its primary key so it needs to be unique. The output schema should be call_id,stat2,stat3, 1,b,c, or (1,k,l) 2,y,z, 3,e,f, The problem is that when i use the keyword DISTINCT in the HIVE query, the DISTINCT applies to the all the colums combined. I want

Distinct values from an array?

佐手、 提交于 2019-12-12 03:44:02
问题 Following tables: CREATE TEMPORARY TABLE guys ( guy_id integer primary key, guy text ); CREATE TEMPORARY TABLE sales ( log_date date, sales_guys integer[], sales smallint ); INSERT INTO guys VALUES(1,'john'),(2,'joe'); INSERT INTO sales VALUES('2016-01-01', '{1,2}', 2),('2016-01-02','{1,2}',4); Following query works great to show names on a given date: SELECT log_date, sales_guys, ARRAY_AGG(guy), sales FROM sales JOIN guys ON guys.guy_id = ANY(sales.sales_guys) GROUP BY log_date, sales_guys,

Select all unique emails inside a column filled with data

放肆的年华 提交于 2019-12-12 03:38:58
问题 I have a column's field filled with all kinds of data from a user request (one request per row). I only need the email addresses from these users' requests, and they are all placed in this column according to the following format: [...data...] Email: mysql@se.com Phone: [...remaining data...] I have found this question: select part of table column data in mysql Which provides a solution for part of the problem: SELECT SUBSTR(message,INSTR(message,'Email: ')+7) FROM user_req_log However, this

MongoDB GROUP function (or Map Reduce if necessary) with PHP- Distinct keys

北战南征 提交于 2019-12-12 03:36:01
问题 Does anyone have a good way to run a group function in PHP with a DISTINCT count? The situation is this: I want to check unique logins to our app. This is how the document in the current collection I'm querying looks like: Array ( [_id] => MongoId Object ( [$id] => 50f6da87686ba9f449000003 ) [userId] => 50f6bd0f686ba91a4000000f [action] => login [time] => 1358355079 What I would like to do is count the UNIQUE userIDs through a group statement by date. This is the group statement that I am

How to Group By make Distinct from two Properties has same entity in C# Linq

你。 提交于 2019-12-12 03:32:18
问题 I'm having Two models Person and Boss. Boss is derived from Person. Here the property ID and SID both are speaking about the Employee ID. The ID Speaks about the Boss and SID speaks about the Assistant Staff. Kindly refer the Model Classes and the Collection public class Person { public int ID { get; set; } public int SID { get; set; } public string Name { get; set; } public string Department { get; set; } public string Gender { get; set; } public string Role { get; set; } } public class Boss

Check existence of distinct values for each group

最后都变了- 提交于 2019-12-12 03:22:21
问题 EDITED: Suppose I have the following table in MySQL: CREATE TABLE `events` ( `pv_name` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL, `time_stamp` bigint(20) UNSIGNED NOT NULL, `value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin, PRIMARY KEY (`pv_name`, `time_stamp`) ) ENGINE=InnoDB; I can find each pv_name that has more than one distinct value in this table using the following query: SELECT events.pv_name FROM events GROUP BY events.pv_name HAVING COUNT(DISTINCT events.value) > 1; The

Distinct count in Cassandra

守給你的承諾、 提交于 2019-12-12 02:24:15
问题 I have a table chat_matches in "cassandra". And want to get the count of all messages from_id to distinct to_id with count of rows(group by to_id). CREATE TABLE chat_matches( chat_id uuid, from_id bigint, to_id bigint, message text, message_send_time timestamp, PRIMARY KEY ((chat_id,from_id),message_send_time) ); 回答1: In cassandra count(*) is a very costly operation, need to scan all the row from all the node just to give you the count and can generate timeout exception. So Instead of using

Eliminate duplicate results in a select query that contains CLOB column

徘徊边缘 提交于 2019-12-12 02:13:12
问题 This is the select query: select orderid,ordernum,orderdate,orderxml from orders The query returns multiple rows with same ordernum. I tried to use DISTINCT and Group BY but orderxml is a clob column. How can I eliminate duplicate ordernums in my query? 回答1: You could use an analytic function to identify a single orderid for each ordernum - probably either min or max, but other functions are available, it depends on what you need - in a subquery, and then filter to only get the rows with the

MySQL SELECT DISTINCT rows (not columns) to filter $_POST for duplicates

偶尔善良 提交于 2019-12-12 01:48:23
问题 I'm trying to filter rows from the MySQL table where all the $_POST data is stored from an online form. Sometimes the user's internet connection stalls or the browser screws up, and the new page after form submission is not displayed (though the INSERT worked and the table row was created). They then hit refresh, and submit their form twice, creating a duplicate row (except for the timestamp and autoincrement id columns). I'd like to select unique form submissions. This has to be a really