Search Results

Search found 7127 results on 286 pages for 'calculated columns'.

Page 32/286 | < Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >

  • T-SQL: from rows to columns but not an actual pivot

    - by Matte
    Is there a T-SQL (SQL Server 2008R2) query to transform TABLE_1 into the expected resultset? TABLE_1 +----------+-------------------------+---------+------+ | IdDevice | Timestamp | M300 | M400 | +----------+-------------------------+---------+------+ | 3 | 2012-12-05 16:29:51.000 | 2357,69 | 520 | | 6 | 2012-12-05 16:29:51.000 | 1694,81 | 470 | | 1 | 2012-12-05 16:29:51.000 | 2046,33 | 111 | +----------+-------------------------+---------+------+ Expected resultset +-------------------------+---------+--------+---------+--------+---------+--------+ | Timestamp | 3_M300 | 3_M400 | 6_M300 | 6_M400 | 6_M300 | 6_M400 | +-------------------------+---------+--------+---------+--------+---------+--------+ | 2012-12-05 16:29:51.000 | 2357,69 | 520 | 1694,81 | 470 | 2046,33 | 111 | +-------------------------+---------+--------+---------+--------+---------+--------+

    Read the article

  • Can DataObjects.NET support SQL identity columns?

    - by Mark
    While there's lots to like about DataObjects.NET, I've found help resources to be a lean, and can't find a solit example of using DataObjects.NET with RDBMS generated primary keys. It would seem as though D4O won't do inserts against SQL Server unless it's in controll of the key. Has anyone solved this in the wild?

    Read the article

  • sql - get the latest date of two columns

    - by stacker
    table1 - date1 datetime not null - date2 nvarchar null I want to get the latest date of this two. select date1, date2, (CASE WHEN date1 > CAST(date2 as DateTime) THEN date1 ELSE date2 END) as DateTime) as LatestDate from table1 please note that date2 can be null. in this case, date1 win.

    Read the article

  • alias some columns names as one field in oracle's join select query

    - by Marecky
    Hi We are developing something like a social networking website. I've got task to do 'follow me' functionality. In our website objects are users, teams, companies, channels and groups (please don't ask why there are groups and teams - it is complicated for me too, but teams are releated to user's talent) Users, teams, channels, companies and groups have all their own tables. I have a query which gets me all the follower's leaders like this select --fo.leader_id, --fo.leader_type, us.name as user_name, co.name as company_name, ch.title as channel_name, gr.name as group_name, tt.name as team_name from follow_up fo left join users us on (fo.leader_id = us.id and fo.leader_type = 'user') left join companies co on (fo.leader_id = co.user_id and fo.leader_type = 'company') left join channels ch on (fo.leader_id = ch.id and fo.leader_type = 'channel') left join groups gr on (fo.leader_id = gr.id and fo.leader_type = 'group') left join talent_teams tt on (fo.leader_id = tt.id and fo.leader_type = 'team') where follower_id = 83 I need to get all fields like: user_name, company_name, channel_name, group_name, team_name as one field in SELECT's product. I have tried to alias them all the same 'name' but Oracle numbered it. Please help :)

    Read the article

  • Get a DB result with a value between two columns values

    - by vitto
    Hi, I have a database situation where I'd like to get a user profile row by a user age range. this is my db: table_users username age email url pippo 15 [email protected] http://example.com pluto 33 [email protected] http://example.com mikey 78 [email protected] http://example.com table_profiles p_name start_age_range stop_age_range young 10 29 adult 30 69 old 70 inf I use MySQL and PHP but I don't know if there is some specific tacnique to do this and of course if it's possible. # so something like: SELECT * FROM table_profiles AS profiles INNER JOIN table_users AS users # can I do something like this? ON users.age IS BETWEEN profiles.start_age_range AND profiles.stop_age_range

    Read the article

  • Display another field in the referenced table for multiple columns with performance issues in mind

    - by israkir
    I have a table of edge like this: ------------------------------- | id | arg1 | relation | arg2 | ------------------------------- | 1 | 1 | 3 | 4 | ------------------------------- | 2 | 2 | 6 | 5 | ------------------------------- where arg1, relation and arg2 reference to the ids of objects in another object table: -------------------- | id | object_name | -------------------- | 1 | book | -------------------- | 2 | pen | -------------------- | 3 | on | -------------------- | 4 | table | -------------------- | 5 | bag | -------------------- | 6 | in | -------------------- What I want to do is that, considering performance issues (a very big table more than 50 million of entries) display the object_name for each edge entry rather than id such as: --------------------------- | arg1 | relation | arg2 | --------------------------- | book | on | table | --------------------------- | pen | in | bag | --------------------------- What is the best select query to do this? Also, I am open to suggestions for optimizing the query - adding more index on the tables etc... EDIT: Based on the comments below: 1) @Craig Ringer: PostgreSQL version: 8.4.13 and only index is id for both tables. 2) @andrefsp: edge is almost x2 times bigger than object.

    Read the article

  • Sql Server problems reading columns with a foreigh key

    - by illdev
    I have a weird situation, where simple queries seem to never finish for instance SELECT top 100 ArticleID FROM Article WHERE ProductGroupID=379114 returns immediately SELECT top 1000 ArticleID FROM Article WHERE ProductGroupID=379114 never returns SELECT ArticleID FROM Article WHERE ProductGroupID=379114 never returns SELECT top 1000 ArticleID FROM Article returns immediately by 'returning' I mean 'in query analyzer the green check mark appears and it says "Query executed successfully"'. I sometimes get the rows painted to the grid in qa, but still the query goes on waiting for my client to time out - 'sometimes': SELECT ProductGroupID AS Product23_1_, ArticleID AS ArticleID1_, ArticleID AS ArticleID18_0_, Inventory_Name AS Inventory3_18_0_, Inventory_UnitOfMeasure AS Inventory4_18_0_, BusinessKey AS Business5_18_0_, Name AS Name18_0_, ServesPeople AS ServesPe7_18_0_, InStock AS InStock18_0_, Description AS Descript9_18_0_, Description2 AS Descrip10_18_0_, TechnicalData AS Technic11_18_0_, IsDiscontinued AS IsDisco12_18_0_, Release AS Release18_0_, Classifications AS Classif14_18_0_, DistributorName AS Distrib15_18_0_, DistributorProductCode AS Distrib16_18_0_, Options AS Options18_0_, IsPromoted AS IsPromoted18_0_, IsBulkyFreight AS IsBulky19_18_0_, IsBackOrderOnly AS IsBackO20_18_0_, Price AS Price18_0_, Weight AS Weight18_0_, ProductGroupID AS Product23_18_0_, ConversationID AS Convers24_18_0_, DistributorID AS Distrib25_18_0_, type AS Type18_0_ FROM Article AS articles0_ WHERE (IsDiscontinued = '0') AND (ProductGroupID = 379121) shows this behavior. I have no idea what is going on. Probably select is broken ;) Anyone can tell me how to handle such a situation? More info, anyone?

    Read the article

  • Groovy: Sorting Columns in a view: list

    - by Luixv
    I have a Groovy application. I am rendering the view list using the following statement: render (view: 'list', model:[reportingInstanceList: reportingInstanceList, reportingInstanceTotal: i, params: params]) The list.gsp is as follows: The view is rendered but the default sorting is not working. <g:sortableColumn class="tabtitle" property="id" title="Id" titleKey="reporting.id" /> <g:sortableColumn class="tabtitle" property="company" title="Company" titleKey="reporting.company" /> Unfortunately the default sorting (by id, by company, etc) are not working. Any hint why? Thanks a lot in advance. Luis

    Read the article

  • Need help with Binary Columns

    - by nusrath
    Hi, I have to query a column containing a Binary column with data like this ®â{Õ¦K!Eòû¦?;#§ø. How can i query this colmn..if I wanted something like: SELECT Name FROM Users WHERE ID = ®â{Õ¦K!Eòû¦?;#§ø THanks

    Read the article

  • Max value amongst 4 columns in a row.

    - by KandadaBoggu
    I have test_scores table with following fields: Table schema: id (number) score1 (number) score2 (number) score3 (number) score4 (number) Sample data: id score1 score2 score3 score4 1 10 05 30 50 2 05 15 10 00 3 25 10 05 15 Expected result set: id col_name col_value 1 score4 50 2 score2 15 3 score1 25 What is a good SQL for this?(I am using MySQL.)

    Read the article

  • Check constraint over two columns

    - by Rippo
    I want to add a Check Constraint to a table for server 2005 but cannot work it out. MemberId ClubId MeetingId 1 100 10 2 100 10 3 100 10 7 101 10 <-This would throw a check constraint 1 100 11 2 100 11 I do not want to have more than one ClubId for a single MeetingId Basically a ClubId can only belong to a single MeetingId but can have more than one member assigned. How do I achieve this?

    Read the article

  • MySQL search a text from two columns

    - by I Like PHP
    i have a table (tbl_world) which look like this id | first_name | last_name | age | class | now i want to search the text which can be anywhere in first_name or in last_name i m using below mysql query "SELECT * FROM tbl_world WHERE REGEXP '".$word."' IN( first_name, last_name)"; where $word is user input (means if i search 'hell' then 'hello' as well as 'wellhell' also returned in result) above query display error, please suggest me optimize method for search in mysql. addition question: should i use LIKR or RLIKE?

    Read the article

  • mysql - combining columns and tables

    - by Phil Jackson
    Hi, I'm not much of a SQL man so I'm seeking help for this one. I have a site where I have a database for all accounts and whatnot, and another for storing actions that the user has done on the site. Each user has their own table but I want to combine the data of each user group ( all users that are "linked together" ) and order that data in the time the actions took place. Heres what I have; <?php $query = "SELECT `TALKING_TO` FROM `nnn_instant_messaging` WHERE `AUTHOR` = '" . DISPLAY_NAME . "' AND `TALKING_TO` != ''"; $query = mysql_query( $query, $CON ) or die( "_error_ " . mysql_error()); if( mysql_num_rows( $query ) != 0 ) { $table_str = ""; $select_ref_clause = "( "; $select_time_stamp_clause = "( "; while( $row = mysql_fetch_array( $query ) ) { $table_str .= "`actvbiz_networks`.`" . $row['TALKING_TO'] . "`, "; $select_ref_clause .= "`actvbiz_networks`.`" . $row['TALKING_TO'] . ".REF`, "; $select_time_stamp_clause .= "`actvbiz_networks`.`" . $row['TALKING_TO'] . ".TIME_STAMP`, "; } $table_str = $table_str . "`actvbiz_networks`.`" . DISPLAY_NAME . "`"; $select_ref_clause = substr($select_ref_clause, 0, -2) . ") AS `REF`, "; $select_time_stamp_clause = substr($select_time_stamp_clause, 0, -2) . " ) AS `TIME_STAMP`"; }else{ $table_str = "`actvbiz_networks`.`" . DISPLAY_NAME . "`"; $select_ref_clause = "`REF`, "; $select_time_stamp_clause = "`TIME_STAMP`"; } $where_clause = $select_ref_clause . $select_time_stamp_clause; $query = "SELECT " . $where_clause . " FROM " . $table_str . " ORDER BY TIME_STAMP"; die($query); $query = mysql_query( $query, $CON ) or die( "_error_ " . mysql_error()); if( mysql_num_rows( $query ) != 0 ) { }else{ ?> <p>Currently no actions have taken place in your network.</p> <?php } ?> The code above returns the sql statement: SELECT ( `actvbiz_networks`.`john_doe.REF`, `actvbiz_networks`.`Emmalene_Jackson.REF`) AS `REF`, ( `actvbiz_networks`.`john_doe.TIME_STAMP`, `actvbiz_networks`.`Emmalene_Jackson.TIME_STAMP` ) AS `TIME_STAMP` FROM `actvbiz_networks`.`john_doe`, `actvbiz_networks`.`Emmalene_Jackson`, `actvbiz_networks`.`act_web_designs` ORDER BY TIME_STAMP I really am learning on my feet with SQL. Its not the PHP I have a problem with ( I can quite happly code away with PHP ) I'ts just help with the SQL statement. Any help much appreciated, REgards, Phil

    Read the article

  • MySQL - how to retrieve columns in same row as the values returned by min/mx

    - by Gala101
    I couldn't frame the Question's title properly.. Suppose a table of weekly movie Earnings as below, MovieName MovieGross WeekofYear Year So how do I get the names of top grossers for each week of this year If I do select MovieName , Max(MovieGross) , WeekofYear from earnings where year = 2010 group by WeekofYear; Then obviously query wont run, select Max(MovieName) , Max(MovieGross) , WeekofYear from earnings where year = 2010 group by WeekofYear; would just give movies starting with lowest alphabet Is using group-concat and then substring-index the only option here? select substring_index(group_concat(MovieName order by MovieGross desc),',',1), Max(MovieGross) , WeekofYear from earnings where year = 2010 group by WeekofYear ; Seems clumsy.. Is there any better way of acieveing this?

    Read the article

  • Converting rows to Columns in SQL

    - by Ram
    I have a table (actually a view, but simplified my example to a table) which gives me some data like this id CompanyName website 1 Google google.com 2 Google google.net 3 Google google.org 4 Google google.in 5 Google google.de 6 Microsoft Microsoft.com 7 Microsoft live.com 8 Microsoft bing.com 9 Microsoft hotmail.com I am looking to convert it to get a result like this CompanyName website1 website2 website3 website 4 website5 website6 ----------- ------------- ---------- ---------- ----------- --------- -------- Google google.com google.net google.org google.in google.de NULL Microsoft Microsoft.com live.com bing.com hotmail.com NULL NULL I have looked into pivot but looks like the record(row values) cannot be dynamic (i.e can only be certain predefined values). Also, if there are more than 6 websites, I want to limit it to the first 6 Dynamic pivot makes sense, but I would have to incorporate it into my view ?? Is there a simpler solution for this ? Here are the SQL scripts CREATE TABLE [dbo].[Company]( [id] [int] NULL, [CompanyName] [varchar](50) NULL, [website] [varchar](50) NULL ) ON [PRIMARY] GO insert into company values (1,'Google','google.com') insert into company values (2,'Google','google.net') insert into company values (3,'Google','google.org') insert into company values (4,'Google','google.in') insert into company values (5,'Google','google.de') insert into company values (6,'Microsoft','Microsoft.com') insert into company values (7,'Microsoft','live.com') insert into company values (8,'Microsoft','bing.com') insert into company values (9,'Microsoft','hotmail.com')

    Read the article

  • T-SQL Query, combine columns from multiple rows into single column

    - by Shayne
    I have seeen some examples of what I am trying to do using COALESCE and FOR XML (seems like the better solution). I just can't quite get the syntax right. Here is what I have (I will shorten the fields to only the key ones): Table Fields ------ ------------------------------- Requisition ID, Number IssuedPO ID, Number Job ID, Number Job_Activity ID, JobID (fkey) RequisitionItems ID, RequisitionID(fkey), IssuedPOID(fkey), Job_ActivityID (fkey) I need a query that will list ONE Requisition per line with its associated Jobs and IssuedPOs. (The requisition number start with "R-" and the Job Number start with "J-"). Example: R-123 | "PO1; PO2; PO3" | "J-12345; J-6780" Sure thing Adam! Here is a query that returns multiple rows. I have to use outer joins, since not all Requisitions have RequisitionItems that are assigned to Jobs and/or IssuedPOs (in that case their fkey IDs would just be null of course). SELECT DISTINCT Requisition.Number, IssuedPO.Number, Job.Number FROM Requisition INNER JOIN RequisitionItem on RequisitionItem.RequisitionID = Requisition.ID LEFT OUTER JOIN Job_Activity on RequisitionItem.JobActivityID = Job_Activity.ID LEFT OUTER JOIN Job on Job_Activity.JobID = Job.ID LEFT OUTER JOIN IssuedPO on RequisitionItem.IssuedPOID = IssuedPO.ID

    Read the article

  • oracle select query - index on multiple columns

    - by CC
    Hello. I'm working on a sql query, and trying to optimise it, because it takes too long to execute. I have a few select and UNION between. Every select is on the same table but with different condition in WHERE clause. Basically I have allways something like : select * from A where field1 <"toto" and field2 IN (...) UNION select * from A where field1 >"toto2" and field2 =(...) UNION .... I have a index on field1 (it a date field, and field2 is a number). Now, when I do the select and if I put only WHERE field1 <'12/12/2010' it does not use the index. I'm using Toad to see the explain plain and it said: SELECT STAITEMENT Optimiser Mode = CHOOSE TABLE ACCESS FULL It is a huge table, and the index on this column is there. Any idea about this optimiser ? And why it does not uses the index ? Another question is , if I have where clause on field1 and field2 , I have to create only one index, or one index for each field ? Thanks alot.

    Read the article

  • Oracle Rows into Columns

    - by user2904845
    Can someone help me design the query to get below o/p. Data I have: Table X: Count Name Amount Days 5 ABC 500 Day1 10 ABC 1000 Day2 3 BCD 100 Day1 4 BDC 200 Day2 Result I need: Name Count AmountDay1 Count AmountDay2 ABC 5 500 10 1000 BCD 3 100 4 200 etc Is this Possible? I tried something with the below query, but not getting the desired o/p select * from X pivot (sum(amount) for days in ('Day1', 'Day2')) Please help I'm using Oracle 11 G

    Read the article

  • created persisted computed columns when the user defined scalar function appears to be non-determini

    - by Ralph Shillington
    I have a scalar UDF that I know to be deterministic, however SQL doesn't. Is there a way to declare it as deterministic so that I can then use it in a persisted computed column definition? further clarification: The purpose of this exercise is that I need to harvest out specific values from an XML column on the row. I can't use the value method of the xml column in my computed column definition, but I can use it in a UDF. I know the xpath query in the value method will produce the same output give the same input so while I certainly understand that not all calls to value will be deterministic I want to assert that mine is.

    Read the article

  • Time diff calculations where date and time are in seperate columns

    - by pedalpete
    I've got a query where I'm trying to get the hours in duration (eg 6.5 hours) between two different times. In my database, time and date are held in different fields so I can efficiently query on just a startDate, or endDate as I never query specifically on time. My query looks like this SELECT COUNT(*), IFNULL(SUM(TIMEDIFF(endTime,startTime)),0) FROM events WHERE user=18 Sometimes an event will go overnight, so the difference between times needs to take into account the differences between the dates as well. I've been trying SELECT COUNT(*), IFNULL(SUM(TIMEDIFF(CONCAT(endDate,' ',endTime),CONCAT(startDate,' ',startTime))),0) FROM events WHERE user=18 Unfortunately I only get errors when I do this, and I can't seem to combine the two fields into a single timestamp.

    Read the article

< Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >