MySQL - 需要选择负值作为正数

时间:2015-07-15 12:49:50

标签: mysql

我有2个MySQL表:subscriptionsgroups.sid中的列subscriptions包含负值,但表id中的列groups包含相同的值,但为正值。

我需要一些方法在加入表格sid之前将groups值转换为正值,或者将表id中的所有值都视为负值的查询

以下是我的查询。它没有返回任何结果,因为列sid包含负值,但列id包含正值

$tmp = mysqli_query($con1,"
SELECT s.uid 
     , s.sid
     , g.title 
  FROM subscriptions s 
  LEFT
  JOIN groups g 
    ON s.sid = g.id  
 WHERE s.uid = $id 
 LIMIT 0,20
") or die('Error8');

1 个答案:

答案 0 :(得分:3)

public class AndroidRssReader extends ListActivity { private RSSFeed myRssFeed = null; ProgressDialog progressDialog; private String kat; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mainrss); Bundle extras = getIntent().getExtras(); if(extras != null) { if(extras.containsKey("cat_name")) { String kat = extras.getString("cat_name"); MyTask task = new MyTask(); task.execute(kat); Toast.makeText(AndroidRssReader.this, kat, Toast.LENGTH_LONG).show(); // here I'm getting kat value properly!!! } } } private class MyTask extends AsyncTask<String, Void, Void>{ @Override protected Void doInBackground(String... params) { String kat = params[0]; Log.d("AJDE!", kat); // here, I'm getting kat value properly in logcat, why kat doesnt go toURL rssUrl ??? try { URL rssUrl = new URL("http://www.example.com/category/" + kat + "/feed/"); SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance(); SAXParser mySAXParser = mySAXParserFactory.newSAXParser(); XMLReader myXMLReader = mySAXParser.getXMLReader(); RSSHandler myRSSHandler = new RSSHandler(); myXMLReader.setContentHandler(myRSSHandler); InputSource myInputSource = new InputSource(rssUrl.openStream()); myXMLReader.parse(myInputSource); myRssFeed = myRSSHandler.getFeed(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { if (myRssFeed!=null) { TextView feedTitle = (TextView)findViewById(R.id.feedtitle); TextView feedSadrzajPosta = (TextView)findViewById(R.id.feedsadrzaj_posta); TextView feedPubdate = (TextView)findViewById(R.id.feedpubdate); TextView feedLink = (TextView)findViewById(R.id.feedlink); feedTitle.setText(myRssFeed.getTitle()); feedSadrzajPosta.setText(myRssFeed.getSadrzajPosta()); feedPubdate.setText(myRssFeed.getPubdate()); feedLink.setText(myRssFeed.getLink()); ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(getApplicationContext(), R.layout.list_black_text,R.id.list_content,myRssFeed.getList()); setListAdapter(adapter); // Toast.makeText(getApplicationContext(), "GGG: " + msg1, Toast.LENGTH_SHORT).show(); }else{ TextView textEmpty = (TextView)findViewById(android.R.id.empty); textEmpty.setText("No Feed Found!"); } super.onPostExecute(result); } /* @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = ProgressDialog.show(AndroidRssReader.this, "Please WAIT", "Loading ..."); } */ } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub Intent intent = new Intent(this,ShowDetails.class); Bundle bundle = new Bundle(); bundle.putString("keyTitle", myRssFeed.getItem(position).getTitle()); bundle.putString("keySadrzajPosta", myRssFeed.getItem(position).getSadrzaj_posta()); bundle.putString("keyLink", myRssFeed.getItem(position).getLink()); bundle.putString("keyPubdate", myRssFeed.getItem(position).getPubdate()); intent.putExtras(bundle); startActivity(intent); } } 功能可以满足您的需求:

  

返回X的绝对值。

请参阅https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_abs