union

Shallow copy of a hashset

喜夏-厌秋 提交于 2021-02-04 11:53:26
问题 Whats the best way of doing it? var set2 = new HashSet<reference_type>(); Traverse the set with a foreach like this. foreach (var n in set) set2.Add(n); Or use something like union like this. set2 = set.UnionWith(set); // all the elements 回答1: Use the constructor: HashSet<type> set2 = new HashSet<type>(set1); Personally I wish LINQ to Objects had a ToHashSet extension method as it does for List and Dictionary . It's easy to create your own of course: public static HashSet<T> ToHashSet<T>(this

Conditional order by clause

穿精又带淫゛_ 提交于 2021-01-29 10:32:25
问题 Below query returning error. Help me under the error and a way to achieve the conditional order by. I am trying to order by grade and name when grade >=8 and grade and marks when grade <8. SELECT name, grade, marks FROM students, grades WHERE min_mark <= marks AND marks <= max_mark AND marks >= 70 UNION SELECT TO_CHAR('NULL') AS name, grade, marks FROM students, grades WHERE min_mark <= marks AND marks <= max_mark AND marks <= 69 order by grade desc,(case when grade >= 8 then name when grade

How can I Create a Multi-Value CrossTab Query in Access 2013?

走远了吗. 提交于 2021-01-28 19:04:06
问题 My Issue I'm working in Access 2013. I have a set of data that needs broken down based on two fields (best done with a crosstab query). My issue is, I need to show the SUM and the COUNT of each 'Value' ([Amt Total] field) -- and unfortunately Access has yet to allow multi-value crosstab queries. For reference purposes if someone is searching online with similar issues - the resulting error if you try to add multiple 'Value' fields in Access: To create a crosstab query, you must specify one or

Using VBA to create a single range from multiple ranges

依然范特西╮ 提交于 2021-01-28 11:41:34
问题 Hello this is my first post as I've always been able to find my answers in previous posts... until now. There must be a post, but I couldn't find one addressing the issue I'm having. My skill level is intermediate at best :-) I have some values in a tabular format. I want to create a range from that which excludes some rows. I felt like I was getting close with a union, but alas, no go. The code example is below. The result was a new range containing only the value of Rng1. Any suggestions

mysql join same table different result set

廉价感情. 提交于 2021-01-28 03:49:03
问题 I would like to combine different results from the same table as one big result. SELECT host_name,stats_avgcpu,stats_avgmem,stats_avgswap,stats_avgiowait FROM sar_stats,sar_hosts,sar_appgroups,sar_environments WHERE stats_host = host_id AND host_environment = env_id AND env_name = 'Staging 2' AND host_appgroup = group_id AND group_name = 'Pervasive' AND DATE(stats_report_time) = DATE_SUB(curdate(), INTERVAL 1 DAY) SELECT AVG(stats_avgcpu),AVG(stats_avgmem),AVG(stats_avgswap),AVG(stats

mysql join same table different result set

跟風遠走 提交于 2021-01-28 02:51:42
问题 I would like to combine different results from the same table as one big result. SELECT host_name,stats_avgcpu,stats_avgmem,stats_avgswap,stats_avgiowait FROM sar_stats,sar_hosts,sar_appgroups,sar_environments WHERE stats_host = host_id AND host_environment = env_id AND env_name = 'Staging 2' AND host_appgroup = group_id AND group_name = 'Pervasive' AND DATE(stats_report_time) = DATE_SUB(curdate(), INTERVAL 1 DAY) SELECT AVG(stats_avgcpu),AVG(stats_avgmem),AVG(stats_avgswap),AVG(stats

mysql join same table different result set

女生的网名这么多〃 提交于 2021-01-27 21:39:31
问题 I would like to combine different results from the same table as one big result. SELECT host_name,stats_avgcpu,stats_avgmem,stats_avgswap,stats_avgiowait FROM sar_stats,sar_hosts,sar_appgroups,sar_environments WHERE stats_host = host_id AND host_environment = env_id AND env_name = 'Staging 2' AND host_appgroup = group_id AND group_name = 'Pervasive' AND DATE(stats_report_time) = DATE_SUB(curdate(), INTERVAL 1 DAY) SELECT AVG(stats_avgcpu),AVG(stats_avgmem),AVG(stats_avgswap),AVG(stats

SQL UNION of two queries, duplicate column name error

走远了吗. 提交于 2021-01-27 14:32:56
问题 I need a UNION of two queries, each of them works separatly, but not together, I get error: duplicate column name zipcode_id , please help. (SELECT * FROM ( (SELECT * FROM jobs AS j LEFT JOIN zipcode AS z ON z.zipcode_id=j.zipcode_id WHERE 1 AND source='student' ORDER BY postdate DESC LIMIT 20) ORDER BY search_order DESC ) s1) UNION ALL (SELECT * FROM ( (SELECT * FROM jobs AS j LEFT JOIN zipcode AS z ON z.zipcode_id=j.zipcode_id WHERE 1 AND source='manager' ORDER BY postdate DESC LIMIT 30,

Aliasing through unions

偶尔善良 提交于 2021-01-27 14:16:51
问题 The 6.5(p7) has a bullet about union s and aggregate s: An object shall have its stored value accessed only by an lvalue expression that has one of the following types: [...] — an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or This is not quite clear what it means. Does it require at least one member or all members to satisfy the strict aliasing rule. Particularly about union s

SQL UNION ALL to eliminate duplicates

帅比萌擦擦* 提交于 2021-01-27 04:34:41
问题 I found this sample interview question and answer posted on toptal reproduced here. But I don't really understand the code. How can a UNION ALL turn into a UNIION (distinct) like that? Also, why is this code faster? QUESTION Write a SQL query using UNION ALL (not UNION) that uses the WHERE clause to eliminate duplicates. Why might you want to do this? Hide answer You can avoid duplicates using UNION ALL and still run much faster than UNION DISTINCT (which is actually same as UNION) by running