访问不顺畅滚动数据库列表视图

问题描述 投票:0回答:1

我的Android应用程序的搜索活动使用列表视图来显示搜索结果,并从存储在资产文件夹中的SQLite数据库获得的列表视图中的每一个项目。问题是,列表视图滚动不顺畅。请帮我。

我的代码:

DatabaseOpenHelper类:

import android.content.Context;

import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

public class DatabaseOpenHelper extends SQLiteAssetHelper {
    private static final String dbname="minip5.db";
    private static final int dbversion=1;

    public DatabaseOpenHelper(Context context){
        super(context,dbname,null,dbversion);
    }
}

DatabaseAccess类:

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;

public class DatabaseAccess {
    private SQLiteOpenHelper openHelper;
    private SQLiteDatabase db;
    private static DatabaseAccess instance;
    public Cursor c;
    //private constructor so that object creation from outside the class 
    is avoided
    private DatabaseAccess(Context context){
        this.openHelper=new DatabaseOpenHelper(context);
    }
    //to return single instance of database
    public static DatabaseAccess  getInstance(Context context){
        if (instance==null)
            instance=new DatabaseAccess(context);
        return instance;
    }

    //to open database
    public void open(){
        this.db=openHelper.getWritableDatabase();
    }
    public void close(){
        if (db!=null)
        this.db.close();
    }
    public ArrayList<searchadapter> st(){
        ArrayList<searchadapter> sea=new ArrayList<>();
        if(c.moveToFirst()){
            do {
                searchadapter a=new searchadapter(c.getString(0));
                sea.add(a);
            }while (c.moveToNext());
        }
        return sea;
    }
    public void run2(String name){
        c=db.rawQuery("select land.State, Avg_Land_Rate, 
        Annual_Avg_Temp_inC, No_of_Companies, annual_avg_rain_inCm, 
        No_of_Schools, No_of_Malls, No_of_Colleges, No_of_Pubs, 
        Literacy_rate_inPercent, Rank_in_Crime_Rate from land, company, 
        education, people, recreation, weather where 
        upper(land.state)='"+name+"' and land.State=company.State and " 
        +"land.State_code=education.State_code and 
        land.State_code=people.State_code 
        land.State_short_code=recreation.State_short_code "+"and 
        land.State_short_code=weather.State_short_code",new String[]{});
    }

searchadapter类:

public class searchadapter {
    private String st;
    public searchadapter(String st){
        this.st=st;
    }
    public String getSt(){
        return st;
    }
    public void setSt(String st){
        this.st=st;
    }
}

SEARCHAD类:

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class searchad extends ArrayAdapter<searchadapter> {
    private Context mcontext;
    private int mresource;
    private int lastpos=-1;

    static class ViewHolder{
        TextView state;
    }

    public searchad(Context context, int resource, ArrayList<searchadapter> objects){
        super(context,resource,objects);
        mcontext=context;
        mresource=resource;
    }
    @Override
    public View getView(int pos, View convertView, ViewGroup parent){
        String state=getItem(pos).getSt();
        searchadapter sa=new searchadapter(state);

        final View result;

        searchad.ViewHolder holder;
        if (convertView==null){
            LayoutInflater inflater=LayoutInflater.from(mcontext);
            convertView=inflater.inflate(mresource,parent,false);
            holder=new searchad.ViewHolder();
            holder.state=(TextView)convertView.findViewById(R.id.txtst);
            result=convertView;

            convertView.setTag(holder);

        }
        else {
            holder=(searchad.ViewHolder)convertView.getTag();
            result=convertView;
        }
    }
}

searchint类:(搜索结果活动课)

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class searchint extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_searchint);
        search();
    }
    ListView listView;
    public void search(){
        listView=(ListView) findViewById(R.id.lsearch);
        listView.setClickable(true);
        DatabaseAccess d=DatabaseAccess.getInstance(getApplicationContext());
        d.open();
        ArrayList<searchadapter> a=d.st();
        d.close();
        searchad adapter1=new searchad(searchint.this,R.layout.search,a);
        listView.setAdapter(adapter1);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int 
            position, long id) {
                TextView tv=(TextView)view.findViewById(R.id.txtst);
                String st=tv.getText().toString();
                DatabaseAccess 
                d=DatabaseAccess.getInstance(getApplicationContext());
                d.open();
                d.run2(st.toUpperCase());
                Intent intent = new Intent(getApplicationContext(), 
                searchres.class);
                startActivity(intent);
            }
        });
    }
}

activity_searchint.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg2"
    tools:context=".searchint">

    <ListView
        android:id="@+id/lsearch"
        android:layout_width="395dp"
        android:layout_height="587dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="8dp" />
</android.support.constraint.ConstraintLayout>
android android-layout android-listview android-sqlite
1个回答
0
投票

我怀疑你的问题可能是由于可提取的行数。

总之提取的行数将是匹配每个表的行的数量的逐渐乘法。

即如果是国家为x,则有: -

  • 10个接地部列具有状态X
  • 4个公司行与状态X
  • 3个教育与行状态X
  • 3个人行与状态X
  • 3个娱乐行与状态x和
  • 3个天气行与状态X

其结果将是似乎什么是数据的相对少量的3,240行。

考虑或许如数据的更合理的有用/可用量: -

  • 30个接地部列具有状态X
  • 20个公司行与状态X
  • 10个教育与行状态X
  • 10个人行与状态X
  • 10个娱乐行与状态x和
  • 10个天气行与状态X

然后600万行会产生,即使真正有用的数据可以表示为90行

测试示例

考虑到用于模仿你的查询如下: -

DROP TABLE IF EXISTS weather;
DROP TABLE IF EXISTS recreation;
DROP TABLE IF EXISTS people;
DROP TABLE IF EXISTS education;
DROP TABLE IF EXISTS company;
DROP TABLE If EXISTS land;
DROP TABLE IF EXISTS state;

CREATE TABLE IF NOT EXISTS land (landid INTEGER PRIMARY KEY, state_reference INTEGER,  state TEXT, state_code TEXT, state_short_code TEXT, land_name TEXT);
CREATE TABLE IF NOT EXISTS company (companyid INTEGER PRIMARY KEY, state_reference INTEGER, state TEXT, company_name TEXT);
CREATE TABLE IF NOT EXISTS education (educationid INTEGER PRIMARY KEY, state_reference INTEGER, state_code TEXT, education_name TEXT);
CREATE TABLE IF NOT EXISTS people (peopleid INTEGER PRIMARY KEY, state_reference INTEGER, state_code TEXT, people_name TEXT);
CREATE TABLE IF NOT EXISTS recreation (recreationid INTEGER PRIMARY KEY, state_reference INTEGER, state_short_code TEXT, recreation_name TEXT);
CREATE TABLE IF NOT EXISTS weather (weatherid INTEGER PRIMARY KEY, state_reference INTEGER, state_short_code TEXT, weather_name TEXT);

-- State Table added to save typing NOTE state_reference was included in all tables to allow state, state_code and state_short_code to be applied automatically (see updates) 
CREATE TABLE IF NOT EXISTS state (stateid INTEGER PRIMARY KEY, state_name TEXT UNIQUE, state_code TEXT UNIQUE, state_short_code TEXT UNIQUE );

-- Build the states (20 should be plenty for testing)
INSERT INTO state (state_name, state_code, state_short_code) VALUES
    ('Alabama','alab','AL'),
  ('Alaska','alas','AK'),
    ('Arizona','ariz','AZ'),
    ('Arkansas','arka','AR'),
    ('California','cali','CA'),
    ('Colorado','colo','CO'),
    ('Connecticut','conn','CT'),
    ('Delaware','dela','DE'),
    ('Florida','flor','FL'),
    ('Georgia','geor','GA'),
    ('Hawaii','hawa','HI'),
    ('Idaho','idah','ID'),
    ('Illinois','illi','IL'),
    ('Indiana','indi','IN'),
  ('Iowa','iowa','IA'),
  ('Kansas','kans','KS'),
    ('Kentucky','kent','KY'),
    ('Louisiana','loui','LA'),
    ('Maine','main','ME'),
    ('Maryland','mary','MD')
;

-- Insert into the 6 tables randomly generating a state reference
INSERT INTO land (land_name,state_reference) VALUES 
    ('LandA', (SELECT abs(random() % 20) + 1))
    ,('LandB', (SELECT abs(random() % 20) + 1))
    ,('LandC', (SELECT abs(random() % 20) + 1))
    ,('LandD', (SELECT abs(random() % 20) + 1))
    ,('LandE', (SELECT abs(random() % 20) + 1))
    ,('LandF', (SELECT abs(random() % 20) + 1))
    ,('LandG', (SELECT abs(random() % 20) + 1))
    ,('LandH', (SELECT abs(random() % 20) + 1))
    ,('LandI', (SELECT abs(random() % 20) + 1))
    ,('LandJ', (SELECT abs(random() % 20) + 1))
    ,('LandK', (SELECT abs(random() % 20) + 1))
    ,('LandL', (SELECT abs(random() % 20) + 1))
    ,('LandM', (SELECT abs(random() % 20) + 1))
    ,('LandN', (SELECT abs(random() % 20) + 1))
    ,('LandO', (SELECT abs(random() % 20) + 1))
    ,('LandP', (SELECT abs(random() % 20) + 1))
    ,('LandQ', (SELECT abs(random() % 20) + 1))
    ,('LandR', (SELECT abs(random() % 20) + 1))
    ,('LandS', (SELECT abs(random() % 20) + 1))
    ,('LandT', (SELECT abs(random() % 20) + 1))
    ,('LandU', (SELECT abs(random() % 20) + 1))
    ,('LandV', (SELECT abs(random() % 20) + 1))
    ,('LandW', (SELECT abs(random() % 20) + 1))
    ,('LandX', (SELECT abs(random() % 20) + 1))
    ,('LandY', (SELECT abs(random() % 20) + 1))
    ,('LandZ', (SELECT abs(random() % 20) + 1))
    ,('Land1', (SELECT abs(random() % 20) + 1))
    ,('Land2', (SELECT abs(random() % 20) + 1))
    ,('Land3', (SELECT abs(random() % 20) + 1))
    ,('Land4', (SELECT abs(random() % 20) + 1))
    ,('Land5', (SELECT abs(random() % 20) + 1))
    ,('Land6', (SELECT abs(random() % 20) + 1))
    ,('Land7', (SELECT abs(random() % 20) + 1))
    ,('Land8', (SELECT abs(random() % 20) + 1))
    ,('Land9', (SELECT abs(random() % 20) + 1))
    ,('Land0', (SELECT abs(random() % 20) + 1))
;

INSERT INTO company (company_name,state_reference) VALUES 
    ('CompA', (SELECT abs(random() % 20) + 1))
    ,('CompB', (SELECT abs(random() % 20) + 1))
    ,('CompC', (SELECT abs(random() % 20) + 1))
    ,('CompD', (SELECT abs(random() % 20) + 1))
    ,('CompE', (SELECT abs(random() % 20) + 1))
    ,('CompF', (SELECT abs(random() % 20) + 1))
    ,('CompG', (SELECT abs(random() % 20) + 1))
    ,('CompH', (SELECT abs(random() % 20) + 1))
    ,('CompI', (SELECT abs(random() % 20) + 1))
    ,('CompJ', (SELECT abs(random() % 20) + 1))
    ,('CompK', (SELECT abs(random() % 20) + 1))
    ,('CompL', (SELECT abs(random() % 20) + 1))
    ,('CompM', (SELECT abs(random() % 20) + 1))
    ,('CompN', (SELECT abs(random() % 20) + 1))
    ,('CompO', (SELECT abs(random() % 20) + 1))
    ,('CompP', (SELECT abs(random() % 20) + 1))
    ,('CompQ', (SELECT abs(random() % 20) + 1))
    ,('CompR', (SELECT abs(random() % 20) + 1))
    ,('CompS', (SELECT abs(random() % 20) + 1))
    ,('CompT', (SELECT abs(random() % 20) + 1))
    ,('CompU', (SELECT abs(random() % 20) + 1))
    ,('CompV', (SELECT abs(random() % 20) + 1))
    ,('CompW', (SELECT abs(random() % 20) + 1))
    ,('CompX', (SELECT abs(random() % 20) + 1))
    ,('CompY', (SELECT abs(random() % 20) + 1))
    ,('CompZ', (SELECT abs(random() % 20) + 1))
    ,('Comp1', (SELECT abs(random() % 20) + 1))
    ,('Comp2', (SELECT abs(random() % 20) + 1))
    ,('Comp3', (SELECT abs(random() % 20) + 1))
    ,('Comp4', (SELECT abs(random() % 20) + 1))
    ,('Comp5', (SELECT abs(random() % 20) + 1))
    ,('Comp6', (SELECT abs(random() % 20) + 1))
    ,('Comp7', (SELECT abs(random() % 20) + 1))
    ,('Comp8', (SELECT abs(random() % 20) + 1))
    ,('Comp9', (SELECT abs(random() % 20) + 1))
    ,('Comp0', (SELECT abs(random() % 20) + 1))
;

INSERT INTO education (education_name,state_reference) VALUES 
    ('EducA', (SELECT abs(random() % 20) + 1))
    ,('EducB', (SELECT abs(random() % 20) + 1))
    ,('EducC', (SELECT abs(random() % 20) + 1))
    ,('EducD', (SELECT abs(random() % 20) + 1))
    ,('EducE', (SELECT abs(random() % 20) + 1))
    ,('EducF', (SELECT abs(random() % 20) + 1))
    ,('EducG', (SELECT abs(random() % 20) + 1))
    ,('EducH', (SELECT abs(random() % 20) + 1))
    ,('EducI', (SELECT abs(random() % 20) + 1))
    ,('EducJ', (SELECT abs(random() % 20) + 1))
    ,('EducK', (SELECT abs(random() % 20) + 1))
    ,('EducL', (SELECT abs(random() % 20) + 1))
    ,('EducM', (SELECT abs(random() % 20) + 1))
    ,('EducN', (SELECT abs(random() % 20) + 1))
    ,('EducO', (SELECT abs(random() % 20) + 1))
    ,('EducP', (SELECT abs(random() % 20) + 1))
    ,('EducQ', (SELECT abs(random() % 20) + 1))
    ,('EducR', (SELECT abs(random() % 20) + 1))
    ,('EducS', (SELECT abs(random() % 20) + 1))
    ,('EducT', (SELECT abs(random() % 20) + 1))
    ,('EducU', (SELECT abs(random() % 20) + 1))
    ,('EducV', (SELECT abs(random() % 20) + 1))
    ,('EducW', (SELECT abs(random() % 20) + 1))
    ,('EducX', (SELECT abs(random() % 20) + 1))
    ,('EducY', (SELECT abs(random() % 20) + 1))
    ,('EducZ', (SELECT abs(random() % 20) + 1))
    ,('Educ1', (SELECT abs(random() % 20) + 1))
    ,('Educ2', (SELECT abs(random() % 20) + 1))
    ,('Educ3', (SELECT abs(random() % 20) + 1))
    ,('Educ4', (SELECT abs(random() % 20) + 1))
    ,('Educ5', (SELECT abs(random() % 20) + 1))
    ,('Educ6', (SELECT abs(random() % 20) + 1))
    ,('Educ7', (SELECT abs(random() % 20) + 1))
    ,('Educ8', (SELECT abs(random() % 20) + 1))
    ,('Educ9', (SELECT abs(random() % 20) + 1))
    ,('Educ0', (SELECT abs(random() % 20) + 1))
;

INSERT INTO education (education_name,state_reference) VALUES 
    ('EducA', (SELECT abs(random() % 20) + 1))
    ,('EducB', (SELECT abs(random() % 20) + 1))
    ,('EducC', (SELECT abs(random() % 20) + 1))
    ,('EducD', (SELECT abs(random() % 20) + 1))
    ,('EducE', (SELECT abs(random() % 20) + 1))
    ,('EducF', (SELECT abs(random() % 20) + 1))
    ,('EducG', (SELECT abs(random() % 20) + 1))
    ,('EducH', (SELECT abs(random() % 20) + 1))
    ,('EducI', (SELECT abs(random() % 20) + 1))
    ,('EducJ', (SELECT abs(random() % 20) + 1))
    ,('EducK', (SELECT abs(random() % 20) + 1))
    ,('EducL', (SELECT abs(random() % 20) + 1))
    ,('EducM', (SELECT abs(random() % 20) + 1))
    ,('EducN', (SELECT abs(random() % 20) + 1))
    ,('EducO', (SELECT abs(random() % 20) + 1))
    ,('EducP', (SELECT abs(random() % 20) + 1))
    ,('EducQ', (SELECT abs(random() % 20) + 1))
    ,('EducR', (SELECT abs(random() % 20) + 1))
    ,('EducS', (SELECT abs(random() % 20) + 1))
    ,('EducT', (SELECT abs(random() % 20) + 1))
    ,('EducU', (SELECT abs(random() % 20) + 1))
    ,('EducV', (SELECT abs(random() % 20) + 1))
    ,('EducW', (SELECT abs(random() % 20) + 1))
    ,('EducX', (SELECT abs(random() % 20) + 1))
    ,('EducY', (SELECT abs(random() % 20) + 1))
    ,('EducZ', (SELECT abs(random() % 20) + 1))
    ,('Educ1', (SELECT abs(random() % 20) + 1))
    ,('Educ2', (SELECT abs(random() % 20) + 1))
    ,('Educ3', (SELECT abs(random() % 20) + 1))
    ,('Educ4', (SELECT abs(random() % 20) + 1))
    ,('Educ5', (SELECT abs(random() % 20) + 1))
    ,('Educ6', (SELECT abs(random() % 20) + 1))
    ,('Educ7', (SELECT abs(random() % 20) + 1))
    ,('Educ8', (SELECT abs(random() % 20) + 1))
    ,('Educ9', (SELECT abs(random() % 20) + 1))
    ,('Educ0', (SELECT abs(random() % 20) + 1))
;

INSERT INTO people (people_name,state_reference) VALUES 
    ('ppplA', (SELECT abs(random() % 20) + 1))
    ,('ppplB', (SELECT abs(random() % 20) + 1))
    ,('ppplC', (SELECT abs(random() % 20) + 1))
    ,('ppplD', (SELECT abs(random() % 20) + 1))
    ,('ppplE', (SELECT abs(random() % 20) + 1))
    ,('ppplF', (SELECT abs(random() % 20) + 1))
    ,('ppplG', (SELECT abs(random() % 20) + 1))
    ,('ppplH', (SELECT abs(random() % 20) + 1))
    ,('ppplI', (SELECT abs(random() % 20) + 1))
    ,('ppplJ', (SELECT abs(random() % 20) + 1))
    ,('ppplK', (SELECT abs(random() % 20) + 1))
    ,('ppplL', (SELECT abs(random() % 20) + 1))
    ,('ppplM', (SELECT abs(random() % 20) + 1))
    ,('ppplN', (SELECT abs(random() % 20) + 1))
    ,('ppplO', (SELECT abs(random() % 20) + 1))
    ,('ppplP', (SELECT abs(random() % 20) + 1))
    ,('ppplQ', (SELECT abs(random() % 20) + 1))
    ,('ppplR', (SELECT abs(random() % 20) + 1))
    ,('ppplS', (SELECT abs(random() % 20) + 1))
    ,('ppplT', (SELECT abs(random() % 20) + 1))
    ,('ppplU', (SELECT abs(random() % 20) + 1))
    ,('ppplV', (SELECT abs(random() % 20) + 1))
    ,('ppplW', (SELECT abs(random() % 20) + 1))
    ,('ppplX', (SELECT abs(random() % 20) + 1))
    ,('ppplY', (SELECT abs(random() % 20) + 1))
    ,('ppplZ', (SELECT abs(random() % 20) + 1))
    ,('pppl1', (SELECT abs(random() % 20) + 1))
    ,('pppl2', (SELECT abs(random() % 20) + 1))
    ,('pppl3', (SELECT abs(random() % 20) + 1))
    ,('pppl4', (SELECT abs(random() % 20) + 1))
    ,('pppl5', (SELECT abs(random() % 20) + 1))
    ,('pppl6', (SELECT abs(random() % 20) + 1))
    ,('pppl7', (SELECT abs(random() % 20) + 1))
    ,('pppl8', (SELECT abs(random() % 20) + 1))
    ,('pppl9', (SELECT abs(random() % 20) + 1))
    ,('pppl0', (SELECT abs(random() % 20) + 1))
;

INSERT INTO recreation (recreation_name,state_reference) VALUES 
    ('recrA', (SELECT abs(random() % 20) + 1))
    ,('recrB', (SELECT abs(random() % 20) + 1))
    ,('recrC', (SELECT abs(random() % 20) + 1))
    ,('recrD', (SELECT abs(random() % 20) + 1))
    ,('recrE', (SELECT abs(random() % 20) + 1))
    ,('recrF', (SELECT abs(random() % 20) + 1))
    ,('recrG', (SELECT abs(random() % 20) + 1))
    ,('recrH', (SELECT abs(random() % 20) + 1))
    ,('recrI', (SELECT abs(random() % 20) + 1))
    ,('recrJ', (SELECT abs(random() % 20) + 1))
    ,('recrK', (SELECT abs(random() % 20) + 1))
    ,('recrL', (SELECT abs(random() % 20) + 1))
    ,('recrM', (SELECT abs(random() % 20) + 1))
    ,('recrN', (SELECT abs(random() % 20) + 1))
    ,('recrO', (SELECT abs(random() % 20) + 1))
    ,('recrP', (SELECT abs(random() % 20) + 1))
    ,('recrQ', (SELECT abs(random() % 20) + 1))
    ,('recrR', (SELECT abs(random() % 20) + 1))
    ,('recrS', (SELECT abs(random() % 20) + 1))
    ,('recrT', (SELECT abs(random() % 20) + 1))
    ,('recrU', (SELECT abs(random() % 20) + 1))
    ,('recrV', (SELECT abs(random() % 20) + 1))
    ,('recrW', (SELECT abs(random() % 20) + 1))
    ,('recrX', (SELECT abs(random() % 20) + 1))
    ,('recrY', (SELECT abs(random() % 20) + 1))
    ,('recrZ', (SELECT abs(random() % 20) + 1))
    ,('recr1', (SELECT abs(random() % 20) + 1))
    ,('recr2', (SELECT abs(random() % 20) + 1))
    ,('recr3', (SELECT abs(random() % 20) + 1))
    ,('recr4', (SELECT abs(random() % 20) + 1))
    ,('recr5', (SELECT abs(random() % 20) + 1))
    ,('recr6', (SELECT abs(random() % 20) + 1))
    ,('recr7', (SELECT abs(random() % 20) + 1))
    ,('recr8', (SELECT abs(random() % 20) + 1))
    ,('recr9', (SELECT abs(random() % 20) + 1))
    ,('recr0', (SELECT abs(random() % 20) + 1))
;

INSERT INTO weather (weather_name,state_reference) VALUES 
    ('WthrA', (SELECT abs(random() % 20) + 1))
    ,('WthrB', (SELECT abs(random() % 20) + 1))
    ,('WthrC', (SELECT abs(random() % 20) + 1))
    ,('WthrD', (SELECT abs(random() % 20) + 1))
    ,('WthrE', (SELECT abs(random() % 20) + 1))
    ,('WthrF', (SELECT abs(random() % 20) + 1))
    ,('WthrG', (SELECT abs(random() % 20) + 1))
    ,('WthrH', (SELECT abs(random() % 20) + 1))
    ,('WthrI', (SELECT abs(random() % 20) + 1))
    ,('WthrJ', (SELECT abs(random() % 20) + 1))
    ,('WthrK', (SELECT abs(random() % 20) + 1))
    ,('WthrL', (SELECT abs(random() % 20) + 1))
    ,('WthrM', (SELECT abs(random() % 20) + 1))
    ,('WthrN', (SELECT abs(random() % 20) + 1))
    ,('WthrO', (SELECT abs(random() % 20) + 1))
    ,('WthrP', (SELECT abs(random() % 20) + 1))
    ,('WthrQ', (SELECT abs(random() % 20) + 1))
    ,('WthrR', (SELECT abs(random() % 20) + 1))
    ,('WthrS', (SELECT abs(random() % 20) + 1))
    ,('WthrT', (SELECT abs(random() % 20) + 1))
    ,('WthrU', (SELECT abs(random() % 20) + 1))
    ,('WthrV', (SELECT abs(random() % 20) + 1))
    ,('WthrW', (SELECT abs(random() % 20) + 1))
    ,('WthrX', (SELECT abs(random() % 20) + 1))
    ,('WthrY', (SELECT abs(random() % 20) + 1))
    ,('WthrZ', (SELECT abs(random() % 20) + 1))
    ,('Wthr1', (SELECT abs(random() % 20) + 1))
    ,('Wthr2', (SELECT abs(random() % 20) + 1))
    ,('Wthr3', (SELECT abs(random() % 20) + 1))
    ,('Wthr4', (SELECT abs(random() % 20) + 1))
    ,('Wthr5', (SELECT abs(random() % 20) + 1))
    ,('Wthr6', (SELECT abs(random() % 20) + 1))
    ,('Wthr7', (SELECT abs(random() % 20) + 1))
    ,('Wthr8', (SELECT abs(random() % 20) + 1))
    ,('Wthr9', (SELECT abs(random() % 20) + 1))
    ,('Wthr0', (SELECT abs(random() % 20) + 1))
;


-- Update the tables to apply the text for the state, state_code and state_short_code 
UPDATE land SET 
    state = (SELECT state_name FROM state WHERE stateid = state_reference), 
    state_code = (SELECT state_code FROM state WHERE stateid = state_reference),
    state_short_code = (SELECT state_short_code FROM state WHERE stateid = state_reference)
;

UPDATE company SET
    state = (SELECT state_name FROM state WHERE stateid = state_reference)
;

UPDATE education SET
    state_code = (SELECT state_code FROM state WHERE stateid = state_reference)
;

UPDATE people SET
    state_code = (SELECT state_code FROM state WHERE stateid = state_reference)
;

UPDATE recreation SET
    state_short_code = (SELECT state_short_code FROM state WHERE stateid = state_reference)
;

UPDATE weather SET
    state_short_code = (SELECT state_short_code FROM state WHERE stateid = state_reference)
;

-- Just in case the tables need to be checked
SELECT * FROM land ;
SELECT * FROM company;
SELECT * FROM education;
SELECT * FROM people;
SELECT * FROM recreation;
SELECT * FROM weather;


-- Now try the query as per the question (well close to it)
-- EXPLAIN QUERY PLAN 
SELECT *
FROM 
    land,company, education, people, recreation, weather 
WHERE upper(land.state)= upper('Maine') 
    AND land.State=company.State 
    AND land.State_code=education.State_code 
    AND land.State_code=people.State_code 
  AND land.State_short_code=recreation.State_short_code 
    AND land.State_short_code=weather.State_short_code
;

-- Calculate the permutations
WITH counts AS ( SELECT 
        (SELECT count() FROM land WHERE upper(state) = upper('Maine')) AS landcount ,
        (SELECT count() FROM company WHERE upper(state) = upper('Maine')) AS companycount,
        (SELECT count() FROM education WHERE upper(state_code) = upper('main')) AS educationcount,
        (SELECT count() FROM people WHERE upper(state_code) = upper('main')) AS peoplecount,
        (SELECT count() FROM recreation WHERE upper(state_short_code) = upper('ME')) AS recreationcount,
        (SELECT count() FROM weather WHERE upper(state_short_code) = upper('ME')) AS weathercount
    )
SELECT *, (landcount * companycount * educationcount * peoplecount * recreationcount * weathercount) AS permutations FROM counts;

结果

运行上面已经从0产生的超过1000行(缅因州(PS所创建的行风险比较低时,不要删除WHERE子句将尝试生成2176782336行(试过这一点,约10分钟后坠毁,我不得不重新启动PC)))。

更多的往往不是会有符合所有标准的0行。不过这里是从生产的90行的运行结果: -

首先,排列(最后查询): -

enter image description here

一些得到的数据,正如你可以看到很可能会是恼人,一旦获取数据的任何合理数量的: -

enter image description here

热门问题
推荐问题
最新问题